Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:有些通知可以取消,有些不可以_Android_Android Notifications - Fatal编程技术网

Android 安卓:有些通知可以取消,有些不可以

Android 安卓:有些通知可以取消,有些不可以,android,android-notifications,Android,Android Notifications,我编写了一个android应用程序来取消所有通知 public class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { Log.d("NotificationListener", "package:" + sbn.getPackageName())

我编写了一个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
有人知道为什么吗

提前谢谢


Eric

某些通知无法取消,因为它们已设置了
标志\u NO\u CLEAR
。检查文档