Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling status bar notification before it is displayed

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

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?

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?

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.

like image 422
Michael A Avatar asked Apr 26 '15 11:04

Michael A


1 Answers

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.

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.

like image 76
Willis Avatar answered Sep 21 '22 15:09

Willis