以下代码在发送两个包含Content1和Content2的不同内容的通知后,会给出相同的内容。生成的活动始终仅显示Content2。可能是什么原因?
public void onReceive(Context context, Intent intent) {
abortBroadcast();
mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence tickerText = intent.getStringExtra("NOTIFICATION_TITLE");
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = intent.getStringExtra("NOTIFICATION_TITLE");
CharSequence contentText = intent.getStringExtra("NOTIFICATION_DETAILS");
Intent notificationIntent = new Intent(context,CustomActivity.class);
notificationIntent.putExtra("TITLE", contentTitle);
notificationIntent.putExtra("DETAILS", contentText);
//notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(notifUUID.hashCode(), notification);
}
答案 0 :(得分:0)
得到了答案!修复很简单 - 只需添加: notificationIntent.setAction(将String.valueOf(notifUUID.hashCode()));
任何唯一值(时间戳也会起作用)设置为意图操作都可以。