10

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?

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
simplified.
  • 101
  • 1
  • 1
  • 3

4 Answers4

6

With API level 18 release, there is now a NotificationListenerService. http://developer.android.com/reference/android/service/notification/NotificationListenerService.html

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
ariets
  • 4,218
  • 4
  • 28
  • 34
2

You might want to have a look at

AccessibilityEvent

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.
dorjeduck
  • 7,624
  • 11
  • 52
  • 66
2

There is currently no generic way to intercept Notifications sent from other applications.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • Thanks for your reply. How about a intercepting notification from a specific application? Is that possible? – simplified. Jun 15 '11 at 16:42
  • Still no luck: it is a security issue (can't have some bad app showing up and intercepting notifications from another app). See http://groups.google.com/group/android-beginners/browse_thread/thread/73cc6d5a60386be8 for a longer discussion. – Femi Jun 15 '11 at 16:46
  • Thanks.. But I was then wondering if it was possible to listener and read notifications from your own application? – simplified. Jun 15 '11 at 16:50
  • No, the limits of what they let you do is cancel all your notifications. You can use `PendingIntent`s and `BroadcastReceiver`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. – Femi Jun 15 '11 at 17:01
  • My 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. – Leonel Galán Apr 30 '12 at 20:04
1

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.

https://androidprogrammatically425516919.wordpress.com/2020/04/19/how-to-listen-whatsapp-notification-on-android-programmatically/