I have built an app that plays audio which must not be interrupted during it plays, because it provides timecode-information to other devices, and will not work properly when the device plays something different in between (e.g. a phone call).
So I need a solution to mute notifications while playing audio. I found out so far:
When setting the permissions previously and guiding the user to allow the app to turn on DND with
startActivityForResult(new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS), 0);
I can activate the "do not disturb" (DND) mode via
NotificationManager.setInterruptionFilter( NotificationManager.INTERRUPTION_FILTER_NONE)
but that will mute the audio-stream of my app also. (see 1)
block phone calls is only possible when the user has root access. I can not ask my users for that and also it will not mute other notifications
I can not use the flight mode, because the app needs WiFi to query the time via NTP from the internet.
Probably a solution is, to set the DND-mode manually and start the app and the stream afterwards. But how is it possible to send the user directly to the DND-menu, so that he/she could enable DND-mode and return to the app by pressing the back button? I only found the Settings-Actions:
ACTION_NOTIFICATION_LISTENER_SETTINGS
ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS
ACTION_SOUND_SETTINGS
which are not the right screens for that. Maybe it is provided somehow to open the quick settings of the DND mode?
So to shorten it up, what I need to do:
User starts audio -> user is asked if he wants to active dnd for no interuption of the audio-playback -> audio-playback is started -> user stops audio -> DND is deactivated
Thanks in advance for ideas on that!