我写了一个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
任何人都知道为什么?
提前致谢。
埃里克