我正在通过通知中的意图发送一些数据(字符串)。但是,当我尝试在通知启动的活动中接收它时,我什么也没收到。这是我的代码。请帮忙。
这是通知的代码:
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 时它被设置为空