Search code examples
javaandroidscreen-recordingheads-up-notifications

Is there a way to hide or disable Heads-Up Notifications temporarily?


I am searching everywhere for this and the closest thing to an answer i got was this which could not block the heads-up notifications.

I am creating a custom screen record app and it annoyies me when heads up notifications show up in my app while recording.

Is there any way i can hide or disable every incoming notification while the screen is recording ?!

I would appreciate if you can give me an example that works on a non rooted device.


Solution

  • Seems you can clear notifications through the NotificationManager as they come.

    In API 23+ you can use both NotificationManager#setNotificationPolicy() and NotificationManager#setInterruptionFilter() (in that specific order) to control which notifications are shown to the user. Permissions are required for those APIs. Notice that this methods seem to be a convenience to be able to access the functionality, but skip implementing a complete NotificationListenerService. That's the only option that can work in a satisfying way

    Details: How do some apps block/replace heads-up notifications?