如何在android中阅读所有即将发布的通知

Adh*_*ham 33 notifications android broadcastreceiver

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

Mon*_*ban 25

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

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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

  • 这个例子对我不起作用我有通知权限,但仍然没有显示任何列表 (3认同)
  • 是否可以阅读已经存在的通知或刚刚发布的新通知? (3认同)

Muk*_*h Y 13

使用NotificationListenerService,我们可以轻松读取所有应用程序的通知.在此查看完整的演示代码