I have made an app that sets notifications in the drop-down status bar of Android phones. However, there is a bug in my code (sometimes the notifications are set, sometimes they are not). I want to be able TO CHECK (in the code) IF THE NOTIFICATION IS VISIBLE TO THE USER. (i.e. can the user see the notification in the status bar?).
How can I do this? (Thanks in advance).
Sample code is greatly appreciated.
You can’t, sorry.Update: Now possible with Android 4.3+ http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications()However, you can always simply
cancel()it — canceling aNotificationthat is not on-screen is perfectly fine. Conversely, you can always safely callnotify()again for the sameNotification, and it too will not cause a problem if theNotificationis already on-screen.EDIT:
NotificationManager.getActiveNotifications() was added in API 23 if you don’t want to use the
NotificationListenerService