Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Silent Mode in android without triggering Do Not Disturb

Having a little trouble bending my head around this one.

In my volume control app I am trying to set the system sound profile to SILENT ONLY without triggering do not disturb, my app has access to modify DND settings and notification access, no issues there.

System Settings has a silent profile that leaves DND off but I cannot find a way to do it using audio manager?

I have attempted to set the mode to silent and then change DND settings using NotificationManager, disabling DND after setting the system to silent sets vibrate, disabling dnd and then setting silent re-activates DND.

Code for reference:

int current = audioManager.getRingerMode();
if (current == AudioManager.RINGER_MODE_VIBRATE) {
         newIcon = Icon.createWithResource(this, R.drawable.silent);
         //ENABLES DND WHEN IT SHOULD ENABLE SILENT
         audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}

Any assistance would be appreciated as this is driving me a little insane.

like image 670
Lee Bailey - LeeDrOiD Avatar asked Sep 21 '19 23:09

Lee Bailey - LeeDrOiD


3 Answers

... but DND is not silent. DND can be configured to to allow priority callers to ring, but silent allows no callers to ring. So users and apps should have the choice.

This code appears to successfully mute the ringer for me (on emulator running API 28) and does not set do-not-disturb mode:-

audio.adjustStreamVolume(AudioManager.STREAM_RING,
                        AudioManager.ADJUST_MUTE, 0);

To reinstate the ringer, do

enter audio.adjustStreamVolume(AudioManager.STREAM_RING,
                        AudioManager.ADJUST_UNMUTE, 0); 
like image 192
user3791713 Avatar answered Oct 08 '22 16:10

user3791713


This indeed appears to be another all too familiar bug in Android, in that setting RINGER_MODE_SILENT doesn't do what the documentation says it should do. I got the desired behaviour by:

  • First setting RINGER_MODE_NORMAL
  • Then setting RINGER_MODE_SILENT
  • Then setting INTERRUPTION_FILTER_ALL to override the erroneously set Do Not Disturb state.

i.e.

audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL);

Hope this helps.

like image 31
biqqles Avatar answered Oct 08 '22 16:10

biqqles


Let me also agree here. I would argue, that DnD is more than just Silence. E.g. there is a potential side effect on notifications.

Now as a user of the phone, just silencing devices, without hiding the notifications is what I want, when traveling, when I am in the meeting.

So as a dev I want to be able to implement such a behavior, but right now DND and silent-mode are merged.

Hence I filed a bug for Android https://issuetracker.google.com/issues/237819541

like image 1
Skip Avatar answered Oct 08 '22 17:10

Skip