通过广播接收方式,根据包名关闭App所有通知。
diff
packages/apps/Settings$ git diff
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d4c54c6ed8..1ce7d4136f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -106,6 +106,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_DREAM_STATE" />
<uses-permission android:name="android.permission.READ_DREAM_SUPPRESSION" />
+ <uses-permission android:name="android.permission.SET_WALLPAPER" />
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
@@ -3542,10 +3543,20 @@
<action android:name="com.android.settings.action.LAUNCH_BLUETOOTH_PAIRING"/>
</intent-filter>/>
</receiver>
+
+ <receiver
+ android:name=".MyReceiver"
+ android:enabled="true"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="com.android.setWallpaper"/>
+ <action android:name="com.android.start_devicetest" />
+ <action android:name="com.android.start_iperf" />
+ <action android:name="com.android.switch_notification" />
+ </intent-filter>
+ </receiver>
diff --git a/src/com/android/settings/MyReceiver.java b/src/com/android/settings/MyReceiver.java
--- a/src/com/android/settings/MyReceiver.java
+++ b/src/com/android/settings/MyReceiver.java
+else if("com.android.switch_notification".equals(action)){
+ String packageName = intent.getStringExtra("packageName");
+ boolean enable = intent.getBooleanExtra("enable",false);
+ INotificationManager mNotificationManager = +INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERV+ICE));
+ try {
+ PackageManager mPackageManager = context.getPackageManager();
+ int uid = +mPackageManager.getApplicationInfo(packageName,PackageManager.GET_ACTIVITIES).uid;
+ Log.i(TAG,"-----------------setNotificationsEnabledForPackage: " + +packageName + ", uid = " + uid);
+ mNotificationManager.setNotificationsEnabledForPackage(packageName, uid, +enable);
+ } catch (Exception e) {
+ Log.e(TAG, "--------------------setNotificationsEnabledForPackage: " + e);
+ }
+ }
测试方法,发送abd命令
bash
am broadcast -a com.android.switch_notification -p com.android.settings --es packageName kr.co.kisvan.andagent --ez enable false