Question

I am using the class AudioManager to mute the device, and i would like to keep the device muted unless otherwise specified by my app or by the user, the main problem is that when the app is closed the device gets UnMuted instantly. below is the code I am using to mute the device.

 AudioManager am =  (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
 am.setStreamMute(AudioManager.STREAM_RING, true);

So far I Have tried all bunch of stuff but I still have not figured out how to get the device to stay muted after closig the App. Any help you could provied will be appreciated.

Was it helpful?

Solution 2

Try setting the ringer mode:

public void setRinger2Silent()
{       
    AudioManager audioManager= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); 
}

OTHER TIPS

This is happening per the documentation:

"The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically."

Use setStreamVolume() (to 0) instead.

EDIT: I see that on some devices this only sets the volume to 1 for the ringer.

Use setRingerMode() to RINGER_SILENT instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top