在状态栏通知显示之前对其进行处理 [英] Handling status bar notification before it is displayed

查看:75
本文介绍了在状态栏通知显示之前对其进行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NotificationListenerService来处理设备通知:

I am using NotificationListenerService to handle device notifications:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {

    Log.d(TAG,"onNotificationPosted posted - ID :" + sbn.getId() + "\t"
            + sbn.getNotification().tickerText + "\t" + sbn.getPackageName());
 }

将通知发布到设备上后,将调用onNotificationPosted()方法.有没有办法在它出现之前将其捕获?

The onNotificationPosted() method is called after the notification has been posted on the device. Is there a way to catch it before it is presented?

我看到阅读通知也可以使用 AccessibilityManager 来实现,但还是通知弹出后阅读.

I saw that reading notifications can also be achieved using the AccessibilityManager but again it's read after the notification popped.

是否可以将设备通知弹出窗口延迟到某个时刻?

Is there a way to delay the device notifications pop-ups until some moment?

我知道我可以使用NotificationListenerService删除通知(在弹出给用户之后)并将其保存,然后尝试稍后重新启动.但是我在重新启动时遇到问题,并且在状态栏通知已经显示之后再次发生这种情况.

I know I can delete a notification using the NotificationListenerService as it come (after it popped to the user) and save it and try to relaunch it later. But I am having issues with the relaunching and again this is happening after the status bar notification is already shown.

推荐答案

当前,使用NotificationListenerService是通知StatusBarNotifications并与之交互的唯一方法.不允许在通知甚至到达状态栏之前对其进行拦截和处理,这将表示相当明显的安全冲突-在此处也可以确认:

At present, using NotificationListenerService is the only way to be notified of and interact with StatusBarNotifications. Intercepting and handling the notifications before they even reach the status bar is not allowed, and would represent a rather notable security violation - this is also confirmed here: https://stackoverflow.com/questions/10286087/intercepting-notifications.

如果这是可能的话,那么应用程序理论上可以在系统范围内阻止所有其他应用程序的所有通知,这不是一件好事.此外,即使使用NotificationListenerService,您也可能只会看到来自其他应用程序的通知,而不会更改或删除它们.修改/取消应用程序通知的方法,即cancelAllNotifications(),仅用于更改由调用应用程序生成的通知.

If this were possible then an application could in theory block all notifications for all other applications system wide, which would not be a good thing. Furthermore, even with NotificationListenerService you may only see notifications from other applications, not alter or delete them. Methods to modify/cancel application notifications, namely cancelAllNotifications(), only serve to alter the notifications generated by the calling application.

这篇关于在状态栏通知显示之前对其进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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