Add a new notification when push notification is received (not replace the previous)

前端 未结 6 1878
予麋鹿
予麋鹿 2021-02-02 16:59

I am using push notifications in my app. I need to display a notification when a push notification delivered. If I send another notification (without clearing the previous notif

6条回答
  •  借酒劲吻你
    2021-02-02 17:39

    We need Unique notification id which will generate the new notifications.

    Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

      @param id An identifier for this notification unique within your application.
      @param notification A {@link Notification} object describing what to show the user. 
      Must not be null.
    
    public void notify(int id, Notification notification)
    {
        notify(null, id, notification);
    }
    

    Example :

    int  id =(int) System.currentTimeMillis();
                mNotificationManager.notify(id, notify);
    

提交回复
热议问题