GCM message is getting overridden

后端 未结 4 1643
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 11:43

I am using GCM push notification to pass some notification to the user. My problem is when am sending single message then this works fine if send more than one then the last

相关标签:
4条回答
  • 2021-01-14 12:12

    Yes agree with Dipo's answer. According to Android Notification Developer Guide This is being overridden due to same notification id for more than one notification.SO the last message is being received on receiver end. You need to Implement random unique Notification id for each notifications. There are number of ways to implement this . You can use this

    int notificationId = new Random().nextInt();
    

    You can also use system time in Mili Seconds for Notification id.Then you need to pass this unique Notification ID to notificationManager.notify()

    Cheers ! Keep Coding

    0 讨论(0)
  • 2021-01-14 12:15

    used this coding in your notification

      int requestID = (int) System.currentTimeMillis();
      PendingIntent intent = PendingIntent.getActivity(context, requestID,
      notificationIntent,0 );
    

    then your notification will not override i hope this will help u

    0 讨论(0)
  • 2021-01-14 12:17

    Make notification id unique for each message. Due to this, it's being overridden.

    0 讨论(0)
  • 2021-01-14 12:36

    Quite late to answer for the thread but felt it will be helpful for someone. The same implementation works fine for FCM firebase implementation as well

    // Get a random value 
    int notificationId = new Random().nextInt();
    // Add the notification ID which is unique as a first value of the notify method.
    notificationManager.notify(notificationId, notificationBuilder.build());
    
    0 讨论(0)
提交回复
热议问题