Ever since heads-up notifications appeared on Android, some people liked it for its quick handling, yet some hated it for showing on top of apps (especi
On Android 18+ there is a NotificationListenerService. This service gets notified when new notifications are shown. Then, I understand there are three ways to act:
NotificationListenerService
doesn't call super.xxx
when receiving a notification, the notification is also showed. So this method seems to not work.NotificationListenerService#getCurrentInterruptionFilter()
. This method could return NotificationListenerService#INTERRUPTION_FILTER_NONE
(or any other of the constants), (haven't tested, should be verified).NotificationListenerService#getCurrentInterruptionFilter()
is final, so it cannot be overridden.NotificationListenerService
About NotificationListenerService, you can see the following samples in GitHub kpbird/NotificationListenerService-Example and in this post.
About NotificationManager, see additional information in this post in StackOverflow (specially interesting the highlighted comment) and in this post.
Example, tests and additional notes
I've uploaded the following repository to GitHub with an example based on kpbird's, to test all the assumptions and provide final conclusions.
Notice that the following steps to enable the permission for the app to be able to access the notifications must be followed in order for the app to function properly. This answer also provides a way to open System Settings in the correct section.
Also, for completeness, the following answer provides a way to check whether the permission is already granted or not.
Additional note: apparently first versions of Marshmallow have a bug where NotificationManager#setInterruptionFilter()
doesn't work. See here and here.