开发者

Listening for Notification on Android

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开发者_Python百科 able to know the contents of it. Is that actually possible and how can it be done?


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


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


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜