我正在创建一个应用程序,要求我向用户发送多个推送通知,这些用户具有不同的值,当用户从状态栏点击它们时将显示这些值。
我正在使用以下代码
制作意图 NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.when = when;
notification.icon = icon;
Intent notificationIntent = new Intent(context,RecentStoryPage.class);
notificationIntent.putExtra("id", id_leader);
notificationIntent.putExtra("title", title);
notificationIntent.putExtra("message", message);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, title, "", intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(Integer.parseInt(id), notification);
当我发送单个通知时,这不会产生任何问题,但每当我发出多个通知时,无论我点击哪个通知,它都会以最近的值打开。
答案 0 :(得分:0)
我弄错了,我把这行错误填满了
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
我应该做的
PendingIntent intent = PendingIntent.getActivity(context, Integer.parseInt(id), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);