Android 上监听通知

发布于 2024-11-15 23:43:59 字数 158 浏览 7 评论 0原文

关于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

§对你不离不弃 2024-11-22 23:43:59

随着 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

难理解 2024-11-22 23:43:59

目前没有通用的方法来拦截从其他应用程序发送的通知。

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

梦回梦里 2024-11-22 23:43:59

您可能想查看

AccessibilityEvent

通知类型

通知状态已更改 - 表示显示通知的事件。

类型:TYPE_NOTIFICATION_STATE_CHANGED

属性:

  • getEventType() - 事件的类型。
  • getClassName() - 源的类名。
  • getPackageName() - 源的包名称。
  • getEventTime() - 事件时间。
  • getText() - 源子树的文本。
  • getParcelableData() - 发布的通知。
  • getText() - 用于提供更多上下文的文本。

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.
烙印 2024-11-22 23:43:59

要监听 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文