Android 上监听通知
关于android编程的通知,我有一些疑问。我已经阅读了 notificationmanager、notification 和 notificationbuilder,但它似乎不允许它监听通知。
我想做的是,当任何应用程序发送通知时,我将能够知道它的内容。这实际上可能吗?如何才能做到?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
随着 API 级别 18 的发布,现在有了一个NotificationListenerService。 http://developer.android.com/reference/android/service/notification /NotificationListenerService.html
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.
您可能想查看
AccessibilityEvent
通知类型
通知状态已更改 - 表示显示通知的事件。
类型:TYPE_NOTIFICATION_STATE_CHANGED
属性:
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:
要监听 Android 中的所有传入通知,您需要使用NotificationListenerService 并在清单文件中声明意图。这样您就可以获得 (android.permission.BIND_NOTIFICATION_LISTENER_SERVICE) 权限
请参阅这篇文章以获得更好的理解和完整的代码。
https://androidprogrammatically425516919.wordpress.com/2020/04/19/how-to-listen-whatsapp-notification-on-android-programmatically/
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/