18

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.

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18

4 Answers4

3

... 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); 
1

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.

biqqles
  • 303
  • 3
  • 10
  • 2
    Still not working for me, you see it briefly set to silent then do not disturb kicks in, subsequently setting the interruption filter to ALL then sets the device back to vibrate. I have at some point inadvertently changed some config on my device (no idea what) and audioManager.adjustStreamVolume(STREAM_RING, ADJUST_MUTE, 0); followed by audioManager.adjustStreamVolume(STREAM_RING, ADJUST_LOWER, ALLOW_RINGER_MODES); results in my device being set to classic silent mode, but it doesnt work on any other devices. – Lee Bailey - LeeDrOiD Oct 22 '19 at 07:49
  • This requires posting a Notification? – IgorGanapolsky May 14 '20 at 19:05
1

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

Skip
  • 6,240
  • 11
  • 67
  • 117
0

There are two views of the world when it comes to DnD: Before Android N and after Android N. Before Android N you could use AudioMamnager.setRingerMode(RINGER_MODE_SILENT) if you're only interested in the ringer. But since Android N, the public api AudioMamnager.setRingerMode(silent) == DND. Therefore, for complete silence, you'd have to toggle DnD.

Also if you want to proceed with toggling DnD, you would also need NotificationPolicyAccess.

UPDATE TO ADDRESS COMMENTS

Android users have a lot of latitude. Latitudes that apps do not have.

For your situation there is good news and there is bad news.

The bad news:

Unfortunately there's no workaround that I can recommend. It is a longstanding, CTS tested behavior that silence == DND. (M -> any app could set MODE_SILENT and DND would turn on) (N+ -> using MODE_SILENT first checks in the app has permission to change DND).

THE GOOD NEWS

First, thanks for sharing your use case. As it turns out, Google's camera app has a recording feature as well. And it uses DND during recording. So DND should be a viable option for your situation. You should be able to check this (I am using a Pixel device).

  1. Start recording a video.
  2. Pull down the quick settings to see the DND tile while the recording is on going.
Isai Damier
  • 976
  • 6
  • 8
  • Is there a reason your app doesn't want to trigger DnD? Do you mind sharing your use case? – Isai Damier Nov 19 '19 at 21:49
  • 1
    The connection between silent mode and DND makes no sense. When you silent your device DND won't automatically turn on. – Spidey Nov 19 '19 at 22:17
  • Not all oems/OS versions offer a non-DnD silence. And those that do offer both. I don't know the history about why they were initially merged (the merge took place in Android M), I suspect it was a simplification because Android didn't offer a non-DnD silence in aosp until very recently. – Isai Damier Nov 19 '19 at 22:40
  • On every device I ever heard of you could silence your phone without turning on DND. I'm talking about regular user usage (e.g. silence your phone in a meeting, it won't turn on DND). Xiaomi Mi A1 (unlike a pixel device) will turn on DND if you do the silencing in code but it won't turn on DND if you do the silence like a regular user. If some very specific devices decide to act differently it's on them, but this isn't and shouldn't be a standard. – Spidey Nov 20 '19 at 07:34
  • Say you were making a recorder app and wanted to silence the device to prevent the ringing from polluting the recording. Should your recorder app turn on DND? – Spidey Nov 20 '19 at 07:40
  • I have updated based on the use case info you share. – Isai Damier Nov 20 '19 at 18:28
  • @Spidey - I wholeheartedly agree. This is extremely annoying since I set my DnD to not allow visuals (notifications) as well, and now if I apply a "silence" profile when entering a meeting, it also hides all notifications, definitely not what I want... – OmerB Dec 30 '19 at 19:34