在显示状态栏通知之前处理状态栏通知

Mic*_*l A 11 android android-notifications

NotificationListenerService用来处理设备通知:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {

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

onNotificationPosted()在设备上发布通知后调用该方法.有没有办法在呈现之前捕获它?

我看到也可以使用AccessibilityManager实现阅读通知, 但在弹出通知后再次阅读.

有没有办法延迟设备通知弹出窗口,直到某个时刻?

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

Wil*_*lis 7

目前,使用NotificationListenerService是获得通知和互动的唯一方式StatusBarNotifications.不允许在通知到达状态栏之前拦截和处理通知,这将代表一个相当显着的安全违规 - 这也在此处得到确认:https://stackoverflow.com/questions/10286087/intercepting-notifications.

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