使用root清除状态栏通知

编程入门 行业动态 更新时间:2024-10-25 08:14:38
本文介绍了使用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处理(请参见此处: github/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: github/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 androidxref/4.2.2_r1/xref/frameworks/base/core/java/android/app/NotificationManager.java ),然后尝试以某种方式在返回的服务上调用cancelAll(例如,再次通过反射).

You could try to obtain an instance of it by calling NotificationManager.getService via reflection (see hidden getService() method in NotificationManager androidxref/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清除状态栏通知

本文发布于:2023-11-27 12:08:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态栏   通知   root

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!