0

在我发送两个内容不同的通知(例如 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);


}
4

1 回答 1

0

得到了答案!修复很简单——只添加了:notificationIntent.setAction(String.valueOf(notifUUID.hashCode()));

设置为意图操作的任何唯一值(时间戳也可以)都可以工作。

于 2011-06-10T16:04:40.100 回答