androidnotificationsandroid-notificationsandroid-statusbarnotification-listener

Android / Reading with all of active status bar notifications


In NotificationListenerService class, there are onNotificationPosted(StatusBarNotification sbn) and onNotificationRemoved(StatusBarNotification sbn) functions, of course.

With onNotificationPosted(StatusBarNotification sbn) function, I can be able to read any new notifications as they come in. Is there any way to read previously posted notifications in the mobile device, that have not yet been dismissed, forever? This has to be done by using my own Android application programmatically.


Solution

  • You can use getActiveNotifications() to get all active notifications which is part of the NotificationListenerService class. The documentation is very clear about this method:

    Request the list of outstanding notifications (that is, those that are visible to the current user). Useful when you don't know what's already been posted.