[英]Android: Some notification can be cancelled and some not
我編寫了一個Android應用來取消所有通知。
public class NotificationListener extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d("NotificationListener", "package:" + sbn.getPackageName());
Log.d("NotificationListener", "tag:" + sbn.getTag());
Log.d("NotificationListener", "id:" + sbn.getId());
cancelAllNotifications();
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.d("NotificationListener", "remove package:" + sbn.getPackageName());
Log.d("NotificationListener", "remove tag:" + sbn.getTag());
Log.d("NotificationListener", "remove id:" + sbn.getId());
}
}
在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>
我可以取消以下包裹通知:
05-19 10:25:22.422 1289 1307 D NotificationListener : remove package:com.android.providers.downloads
05-19 10:25:22.422 1289 1307 D NotificationListener : remove tag:1:com.android.vending
05-19 10:25:22.422 1289 1307 D NotificationListener : remove id:0
但是我無法取消以下軟件包通知:
05-19 10:25:20.492 1289 1306 D NotificationListener : package:com.android.settings
05-19 10:25:20.492 1289 1306 D NotificationListener : tag:null
05-19 10:25:20.492 1289 1306 D NotificationListener : id:2130837807
有人知道為什么嗎?
提前致謝。
埃里克
某些通知無法取消,因為它們已使用FLAG_NO_CLEAR
設置。 在此處檢查文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.