1

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.

1
  • When you say closing you mean destroying or getting on pause? Dec 31, 2013 at 17:30

2 Answers 2

2

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.

1

Try setting the ringer mode:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.