Reputation: 8172
I'd like to be able to listen for notifications being sent to the status bar, and intercept and suppress (temporarily) those notifications.
I've seen AccessabilityEvent.TYPE_NOTIFICATION_STATE_CHANGED, and NotificationListenerService.
However, I just don't want to be informed when a notification is displayed, I want to prevent the notification from being displayed.
I can see how this could potentially be a security threat, so I can understand if it's not possible. Is this possible? If so, how would I go about doing it?
Upvotes: 0
Views: 98
Reputation: 772
I think you're on the right track with the NotificationListenerService. Google has made these API's available from Android 4.3 on, so an application using this method would just be available for new devices.
In the following blogpost you can find an example of what you can do with the NotificationListenerService: http://weimenglee.blogspot.ch/2014/03/android-tip-notification-listener.html
The basic idea is to implement the onNotificationPosted()
method, which gives you a StatusBarNotification
instance. You should then be able to cancel the notification with this.cancelNotification(
notif.getPackageName(),
notif.getTag(),
notif.getId());
See the blogpost for a further description of what to extend and how to implement the methods.
Hope this helps.
Upvotes: 1