1

I am building an app that needs to mess with the user's sound. It is all fun and games until I need to turn off the user's sound.

I have the following piece of code:

AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

int streamVolume = am.getStreamVolume(AudioManager.STREAM_RING);
int ringerMode = am.getRingerMode();
int mode = am.getMode();

// When streamVolume == 0, this turns on "Do not disturb"
// I don't want that...
am.setStreamVolume(AudioManager.STREAM_RING, streamVolume, AudioManager.FLAG_PLAY_SOUND);
am.setRingerMode(ringerMode);
am.setMode(mode);

We would expect that this piece of code changes absolutely nothing, however when we've got our phone on vibration for example, therefore streamVolume=0, "Do not disturb" mode is turned on.

My question is: How do I disable the sound on the ring stream without that enabling "Do not disturb"?

To summarize:

am.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_PLAY_SOUND);

Turns on "Do not disturb", how does one avoid that?

  • Did you ever find a way around this? Turning on silent mode through the system UI manually does not enable DND! Can you help me find how the system runs this code in the AOSP source code? – Flyview Aug 31 '19 at 17:35

0 Answers0