문제

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.

도움이 되었습니까?

해결책 2

Try setting the ringer mode:

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top