gpt4 book ai didi

android - 使用root清除状态栏通知

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:09:28 24 4
gpt4 key购买 nike

我目前正在开发一款使用无障碍服务 来处理通知的应用。特别烦人的是第三方应用无法清除状态栏通知,除了启动与通知相关联的 Intent (并启动应用)。

我已经搜索了很长时间来使用 root 关闭通知或清除完整列表,但我没有找到。

我想我记得我看到的一个应用程序通过快速打开状态栏并以编程方式单击清除按钮来清除状态栏,但我找不到了,我认为它是在 Android 2.2 上。

我想知道是否有一种方法可以使用某种数据库 或通过简单的SU 调用与状态栏通知进行交互。

最佳答案

更新 - 请参阅下面的工作解决方案

所有这些东西都由 NotificationManagerService 处理(参见此处:https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/NotificationManagerService.java)。我认为您尤其会对 void cancelAll(int userId) 方法感兴趣。当您在状态屏幕上按下清除时,实际调用的是该方法(使用 ActivityManager.getCurrentUser() 作为参数)。

您可以尝试通过反射调用 NotificationManager.getService 来获取它的实例(请参阅 NotificationManager http://androidxref.com/4.2.2_r1/xref/frameworks/base/core/java/android/app/NotificationManager.java 中隐藏的 getService() 方法),然后尝试以某种方式在返回的服务上调用 cancelAll(例如再次通过反射)。

更新

我找到了一种更简单的方法来通过状态栏服务清除通知。以下代码应该有效:

IBinder b = (IBinder) Class.forName("android.os.ServiceManager").getMethod("getService", new Class[] {
String.class
}).invoke(null, new Object[] {
"statusbar"
});

Object iFace = Class.forName("com.android.internal.statusbar.IStatusBarService$Stub").getDeclaredMethod("asInterface", new Class[] {
IBinder.class
}).invoke(null, new Object[] {
b
});

iFace.getClass().getMethod("onClearAllNotifications", new Class[0]).invoke(iFace, (Object[]) null);

如果您没有以 root 身份运行,这将抛出 SecurityException,但如果您具有 root 权限,则会成功清除通知

关于android - 使用root清除状态栏通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com