Listening for Notification on Android

13,451

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

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.

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.

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

Share:
13,451
simplified.
Author by

simplified.

Updated on June 14, 2022

Comments

  • simplified.
    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.
    simplified. almost 13 years
    Thanks for your reply. How about a intercepting notification from a specific application? Is that possible?
  • Femi
    Femi almost 13 years
    Still 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/thre‌​ad/… for a longer discussion.
  • simplified.
    simplified. almost 13 years
    Thanks.. But I was then wondering if it was possible to listener and read notifications from your own application?
  • Femi
    Femi almost 13 years
    No, the limits of what they let you do is cancel all your notifications. You can use PendingIntents and BroadcastReceivers 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
    Leonel Galán about 12 years
    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.