Listening for Notification on Android
Solution 1
With API level 18 release, there is now a NotificationListenerService. http://developer.android.com/reference/android/service/notification/NotificationListenerService.html
Solution 2
There is currently no generic way to intercept Notifications sent from other applications.
Solution 3
You might want to have a look at
NOTIFICATION TYPES
Notification state changed - represents the event showing Notification.
Type: TYPE_NOTIFICATION_STATE_CHANGED
Properties:
- getEventType() - The type of the event.
- getClassName() - The class name of the source.
- getPackageName() - The package name of the source.
- getEventTime() - The event time.
- getText() - The text of the source's sub-tree.
- getParcelableData() - The posted Notification.
- getText() - Text for providing more context.
Solution 4
To Listen all incoming notifications in android you need to use NotificationListenerService and declare intent in manifest file. so that you can get the (android.permission.BIND_NOTIFICATION_LISTENER_SERVICE) Permission
See this post for better understanding and complete code.
simplified.
Updated on June 14, 2022Comments
-
simplified. almost 2 years
I have some queries when it comes to notification on android programming. I have read up on the notificationmanager, notification and notificationbuilder but it doesn't seem to allow it to listen for notifications.
What I am trying to do is when a notification is send by any application, I will be able to know the contents of it. Is that actually possible and how can it be done?
-
simplified. almost 13 yearsThanks for your reply. How about a intercepting notification from a specific application? Is that possible?
-
Femi almost 13 yearsStill no luck: it is a security issue (can't have some bad app showing up and intercepting notifications from another app). See groups.google.com/group/android-beginners/browse_thread/thread/… for a longer discussion.
-
simplified. almost 13 yearsThanks.. But I was then wondering if it was possible to listener and read notifications from your own application?
-
Femi almost 13 yearsNo, the limits of what they let you do is cancel all your notifications. You can use
PendingIntent
s andBroadcastReceiver
s to listen for clicks on your notifications but if you need to keep track of the contents of your notifications you have to do that manually when you create them. -
Leonel Galán about 12 yearsMy guess is that you can (see Tasker or similar Apps). This apps need to be added in the Accessibility settings, before being able to do so.