[英]Android: Some notification can be cancelled and some not
I write an android app to cancel all notifications. 我编写了一个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());
}
}
in AndroidManifest.xml 在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>
I can cancel the following packages notifications: 我可以取消以下包裹通知:
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
But I cannot cancel the following packages notifications: 但是我无法取消以下软件包通知:
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
Anyone knows why? 有人知道为什么吗?
Thanks in advance. 提前致谢。
Eric 埃里克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.