我的应用程序处理推送通知,并使用
在状态栏中显示多个通知notificationmanager.notify(id, notification);
其中id是动态int。现在我想获得状态栏中点击通知的“id”。我通过
传递“id”notificationIntent.putExtra("notifyId", id);
但它总是返回最新收到的通知的“id”。如何获得相应点击通知的“id”?
用于显示通知的代码:
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
Random generator = new Random();
int i = generator.nextInt(10) + 1;
// Set Notification Title
String strtitle = getString(R.string.notificationtitle);
// Set Notification Text
String strtext = getString(R.string.notificationtext);
Notification notification = new Notification(icon, strtext, when);
// Open NotificationView Class on Notification Click
Intent notificationIntent = new Intent(this, NotificationView.class);
// Send data to NotificationView Class
notificationIntent.putExtra("title", title);
notificationIntent.putExtra("text", message);
notificationIntent.putExtra("notifyId", i);
PendingIntent intent = PendingIntent.getActivity(MyActivity.this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(MyActivity.this, "Title",
message, intent);
// Create Notification Manager
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Build Notification with Notification Manager
notificationmanager.notify(i, notification);
答案 0 :(得分:0)
PendingIntent.FLAG_UPDATE_CURRENT
更改为PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT