使用root清除状态栏通知 [英] Using root to clear the status bar notifications

查看:117
本文介绍了使用root清除状态栏通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用可访问性服务处理通知的应用程序.尤其令人烦恼的是,第三方应用程序无法清除状态栏通知,只能启动链接到该通知的意图(并启动该应用程序).

I am currently working on an app using an accessibility service to handle notifications. What is particularly annoying is there is no way for third party apps to clear the status bar notifications, other than launching the intent linked to the notification (and launch the app).

我已经搜索了很长时间,以找到使用root取消通知或清除完整列表的方法,但是我失败了.

I have searched for a long time for a way to use root to dismiss a notification or clear the complete list, but I have failed.

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

I think I remember an app I saw that cleared the status bar by quickly opening the status bar and clicking the clear button programmatically, but I can't find it anymore, and I think it was on Android 2.2.

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

I was wondering if there was a way to interact with the status bar notifications using some kind of database or with a simple SU call.

推荐答案

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

UPDATE - See working solution below

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

All this stuff gets handled by the NotificationManagerService (see here: https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/NotificationManagerService.java). I think in particular you'd be interested in the void cancelAll(int userId) method. When you press clear on the status screen that's the method that actually gets invoked (with ActivityManager.getCurrentUser() as parameter).

您可以尝试通过反射调用NotificationManager.getService来获取它的实例(请参见NotificationManager

You could try to obtain an instance of it by calling NotificationManager.getService via reflection (see hidden getService() method in NotificationManager http://androidxref.com/4.2.2_r1/xref/frameworks/base/core/java/android/app/NotificationManager.java) and then try to somehow invoke cancelAll on the returned service (e.g. via reflection again).

更新

我发现了一种通过状态栏服务清除通知的简便方法.以下代码应该可以工作:

I found an easier way to clear notifications via the statusbar service. The following code should work:

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);

如果您不是以超级用户身份运行,则将抛出SecurityException;如果您具有超级用户权限,则将成功清除通知

This will throw a SecurityException if you are not running as root but successfully clears notifications if you have root permissions

这篇关于使用root清除状态栏通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆