Android: Manage multiple push notification in device of an app

让人想犯罪 __ 提交于 2019-12-03 03:17:30

Try to put different notification id (i.e. nid) in intent and notify instead of 0 for each new notification this will prevent over writing your notification

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

and

notificationManager.notify(nid, notification);

Hope this will help you

Rooban

Get random numbers:

Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;

Instead of:

notificationManager.notify(0, notification);

use:

notificationManager.notify(m, notification);

hello you need to pass unique notification id in notify method. Below is the code for pass unique notification id:

//"CommonUtilities.getValudeFromOreference" is the method created by me to get value from savedPreferences.
String notificationId = CommonUtilities.getValueFromPreference(context, Global.NOTIFICATION_ID, "0");
int notificationIdinInt = Integer.parseInt(notificationId);

notificationManager.notify(notificationIdinInt, notification);

// will increment notification id for uniqueness
notificationIdinInt = notificationIdinInt + 1;
CommonUtilities.saveValueToPreference(context, Global.NOTIFICATION_ID, notificationIdinInt + "");
//Above "CommonUtilities.saveValueToPreference" is the method created by me to save new value in savePreferences.

Let me know if you need more detail information or any query. :)

You need to update your Notification ID when you fire a Notification. in

notificationManager.notify(ID, notification);

How?

To set up a notification so it can be different, issue it with a notification ID by calling NotificationManager.notify(ID, notification). To change this notification once you've issued it, create a NotificationCompat.Builder object, build a Notification object from it, and issue the Notification with the Different ID you are not used previously.

If the previous notification is still visible, the system updates it from the contents of the Notification object. If the previous notification has been dismissed, a new notification is created instead.

For more information go to official docs

Makvin
notificationManager.notify(Different_id_everytime, notification);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!