我不知道有人能幫助我。我試圖在收到短信時顯示一個toast元素。這敬酒應包含具有圖像(SMS圖標)和2個textviewsShow Broadcast Toast來自BroadcastReceiver
如果我把從活動下面的方法,它按預期工作(發件人,消息)的佈局......
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();
}
但是,如果我試圖從我SMSReceiver調用以同樣的方式相同的代碼,我得到:
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
可有人請告知我如何從一個意圖做tihs。我認爲這個問題與跨線程有關,但我不確定如何繼續。我見過一些例子在線,但他們似乎要麼使用過時的代碼或只顯示簡單的文本
可有人請點我在正確的方向
非常感謝
任何理由/爲downvote建設性的批評? – Basic 2013-08-05 16:28:04