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
相关推荐
graceyun3 小时前
C语言进阶习题【1】指针和数组(4)——指针笔试题3
android·java·c语言
2401_897916068 小时前
Android 自定义 View _ 扭曲动效
android
天花板之恋8 小时前
Android AutoMotive --CarService
android·aaos·automotive
susu108301891112 小时前
Android Studio打包APK
android·ide·android studio
2401_8979078612 小时前
Android 存储进化:分区存储
android
Dwyane0319 小时前
Android实战经验篇-AndroidScrcpyClient投屏一
android
FlyingWDX19 小时前
Android 拖转改变视图高度
android
_可乐无糖19 小时前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
一名技术极客1 天前
Python 进阶 - Excel 基本操作
android·python·excel
我是大佬的大佬1 天前
在Android Studio中如何实现综合实验MP3播放器(保姆级教程)
android·ide·android studio