我通過通知的意圖發送一些數據(字符串)。但是,當我嘗試通過通知發起的活動接收它時,我什麼也收不到。這是我的代碼。請幫忙。如何檢索通過意圖傳遞的數據?
這是通知代碼:
int icon=R.drawable.ic_launcher;
String ticket="Encrypted message";
long when=System.currentTimeMillis();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Context context1 =getApplicationContext();
String expandedText="You've received an encrypted message, click to view";
String expandedTitle="Encrypted Message";
Notification notification = new Notification(icon, ticket, when);
Intent intent1=new Intent(context,Try.class);
intent1.putExtra("MSG","Jumbo");
PendingIntent launchIntent=PendingIntent.getActivity(context,0, intent1,0);
notification.setLatestEventInfo(context,expandedTitle,expandedText,launchIntent);
mNotificationManager.notify(1,notification);
這裏是我如何接受它在Try.class:
t = (TextView)findViewById(R.id.dec);
String d = "";
Intent I = getIntent();
d = I.getStringExtra("MSG");
String text = "This is an example";
t.setText(d);
沒有錯誤 - TextView的設置爲什麼都沒有,當我運行它
它在'onCreate()'方法 – Saturnian