-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推送通知