【问题标题】:values for the intent remain the updated one when making multiple notification for push notification为推送通知制作多个通知时,意图的值保持更新
【发布时间】:2014-04-01 14:52:57
【问题描述】:

我正在制作一个应用程序,它需要我向用户发送多个推送通知,这些推送通知具有不同的值,当用户从状态栏中单击它们时会显示这些值。

我正在使用以下代码制定意图

     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);  

当我发送单个通知时,这不会产生任何问题,但是每当我发送多个通知时,无论我点击哪个通知,它总是以最近的值打开。

【问题讨论】:

    标签: android android-intent notifications android-notifications


    【解决方案1】:

    我弄错了,我把这行错误填满了

    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    我应该做的

     PendingIntent intent = PendingIntent.getActivity(context, Integer.parseInt(id), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 2018-07-18
      • 2015-05-12
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多