-1
A
回答
0
它将从工作:采用Android 4.3(JELLY_BEAN_MR2)。
添加到您的清单新的权限
android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
。创建NotificationListenerService类并添加到清单。
从谷歌开发者:
必须由NotificationListenerService要求,以确保 只有系统可以绑定到它。
的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>
- 覆盖的
onNotificationPosted()
。
NotificationListenerService类别:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationListenerService extends NotificationListenerService {
@Override
public void onNotificationPosted(final StatusBarNotification sbn) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// Here you need to play with the sbn object and get the data that you want from it.
//sbn.getPackageName()
Notification notification = sbn.getNotification();
Bundle extras = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
extras = notification.extras;
}
if (extras != null) {
extras.get("android.title");
}
}
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
}
@Override
@TargetApi(Build.VERSION_CODES.N)
public void onListenerDisconnected() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// Notification listener disconnected - requesting rebind
requestRebind(new ComponentName(this, NotificationListenerService2.class));
}
}
}
简单示例应用:https://github.com/kpbird/NotificationListenerService-Example/
相关问题
- 1. 阅读android通知6.0
- 2. 阅读Android上的现有通知
- 3. Android收到通知
- 4. 阅读通知表
- 5. 收到通知时点亮屏幕android
- 6. Android Facebook SDK 3.0阅读通知
- 7. iOS版 - 阅读,一旦收到推送通知
- 8. Android - 通知收到事件?
- 9. 收到JMS消息时收到通知
- 10. 阅读侏儒壳通知
- 11. 实时更新:订阅通知?
- 12. 接收Android通知
- 13. 如何知道收到的邮件和阅读邮件
- 14. 收到servlet响应时的通知
- 15. 如何在没有AppDelegate的iOS中收到推送通知时收到通知?
- 16. 阅读PhoneGap中的OneSignal通知标题
- 17. 没有收到使用Instagram实时API的通知
- 18. 如何在Rxjs主题订阅/取消订阅时收到通知
- 19. 收件人阅读EWS通知电子邮件地址
- 20. 当你收到一个文件时在android上的通知
- 21. 如何阅读和打开Android中的所有通知?
- 22. 订阅BLE GAT通知Android
- 23. 阅读的Android
- 24. 阅读的Android
- 25. 如何阅读收到的短
- 26. 基于订阅的通知实施
- 27. XMPP的strophe收到通知订阅当用户注销
- 28. 通过JSON格式实时通知android
- 29. Pushwoosh - 原生Android - 未收到通知
- 30. 未收到Android推送通知