NotificationManager receives notification by identifier

Does anyone know how to get an id notification? I want this when you receive a new notification, if it is still displayed in the Android status bar, in order to receive information and add it to the new notification. Thanks.

+6
source share
2 answers

NotificationManager does not provide you with a way to search for existing notifications by ID. If you want to update the notification, post a new notification, but use the same identifier. It will either show it as new or update an existing notification with this identifier.

+11
source

You can get the active notification list from the NotificationManager.

public boolean isNotificationActive(int notificationId) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications(); for(StatusBarNotification notification: barNotifications) { if (notification.getId() == notificationId) { return true; } } return false; } 
0
source

Source: https://habr.com/ru/post/969758/


All Articles