下面我有代码两个通知,并在意图我传递临时演员key1
和key2
但在NotificationPillDescription.class
我只能使用getExtras获得key1。无法从使用通知的未决意图调用的意图中获得额外信息?
//通知代码的第一个通知
Notification notification = new Notification(R.drawable.ic_launcher, "Take your morning pill!", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
Bundle extras = new Bundle();
extras.putString("Key1", String.valueOf(1));
notifyIntent.putExtras(extras);
contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
notificationManager.notify(dataProvider.notificationId++, notification);
//通知代码对于第二个通知
notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
Bundle extras = new Bundle();
extras.putString("Key2", String.valueOf(2));
notifyIntent.putExtras(extras);
contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
notificationManager.notify(dataProvider.notificationId++, notification);
//代码NotificationPillDescription.class
Bundle extras = getIntent().getExtras();
if(extras != null){
if(extras.containsKey(String.valueOf(1)))
{
Log.d("Pill Id0",extras.getString(String.valueOf(1)));
}
else
{
Log.d("Pill Id1",extras.getString(String.valueOf(2)));
}
}