Android11.0系统关闭App所有通知

通过广播接收方式,根据包名关闭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
相关推荐
发飙的蜗牛'15 分钟前
23种设计模式
android·java·设计模式
花追雨9 小时前
Android -- 双屏异显之方法一
android·双屏异显
小趴菜82279 小时前
安卓 自定义矢量图片控件 - 支持属性修改矢量图路径颜色
android
氤氲息10 小时前
Android v4和v7冲突
android
KdanMin10 小时前
高通Android 12 Launcher应用名称太长显示完整
android
chenjk410 小时前
Android不可擦除分区写文件恢复出厂设置,无法读写问题
android
袁震10 小时前
Android-Glide缓存机制
android·缓存·移动开发·glide
工程师老罗10 小时前
Android笔试面试题AI答之SQLite(2)
android·jvm·sqlite
User_undefined11 小时前
uniapp Native.js 调用安卓arr原生service
android·javascript·uni-app
安小牛11 小时前
android anr 处理
android