Listening for Notification on Android

2019-04-05 18:57发布

问题:

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?

回答1:

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



回答2:

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



回答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.