如何在android中阅读所有即将到来的通知 [英] How to read all the coming notifications in android

查看:13
本文介绍了如何在android中阅读所有即将到来的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 android 中阅读所有即将到来的通知.是否可以使用广播接收器来收听传入的通知以及读取通知信息的能力.

How to read all the coming notifications in android. Is it possible to use the broadcast receiver to listen the incoming notifications and the ability to read the notifications information.

推荐答案

首先,您必须在清单中声明接收通知的意图,以便您可以获得 android.permission.BIND_NOTIFICATION_LISTENER_SERVICE 权限.

First you must declare your intent to receive notifications in your manifest, so that you can get the android.permission.BIND_NOTIFICATION_LISTENER_SERVICE permission.

AndroidManifest.xml:

AndroidManifest.xml:

<service android:name=".NotificationListener"
         android:label="@string/service_name"
         android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
    <intent-filter>
        <action android:name="android.service.notification.NotificationListenerService" />
    </intent-filter>
</service>

然后创建一个 NotificationListenerService 类并覆盖 onNotificationPosted 函数.

Then create a NotificationListenerService class and override the onNotificationPosted function.

有关更多信息,请阅读此处的开发者参考:https://developer.android.com/reference/android/service/notification/NotificationListenerService.html

For more information, read the developer reference here: https://developer.android.com/reference/android/service/notification/NotificationListenerService.html

另请查看这个简单的示例应用程序以获取实施指南:https://github.com/kpbird/NotificationListenerService-Example/

Also look at this simple example application for implementation guidance: https://github.com/kpbird/NotificationListenerService-Example/

这篇关于如何在android中阅读所有即将到来的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆