I wonder if anyone can help me. I am trying to show a toast item when an SMS is received. This toast should contain a layout with an image (SMS icon) and 2 text views (sender, message)
If I call the next method from the action, it works as expected ...
public void showToast(Context context, String name, String message) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_sms,
(ViewGroup) findViewById(R.id.toast_sms_root));
TextView text = (TextView) layout.findViewById(R.id.toastsms_text);
text.setText(message);
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
However, if I try to call the same code in the same way from my SMSReceiver, I get:
The method getLayoutInflater() is undefined for the type SmsReceiver
The method findViewById(int) is undefined for the type SmsReceiver
The method getApplicationContext() is undefined for the type SmsReceiver
Can someone please advise how I can do this from intention. I assume the problem is with cross-threads, but I'm not sure how to do this. I saw a couple of examples on the Internet, but they seem to either use outdated code or just display plain text
Can someone point me in the right direction
Many thanks