How to disable the sound speaker in android

Can someone tell me how to turn off the sound speaker in Android. I tried

mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true); 

and

 mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC,true); 

But that will not work.

+4
source share
1 answer

Basically you need to know which stream you plan to capture, from what I heard AudioManager is an error. If your idea is to close all existing streams and play only your sound, you can trick other noise-creating applications by doing the following:

 AudioManager.setMode(AudioManager.MODE_IN_CALL); AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true); 

then delete it later

 AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false); AudioManager.setMode(AudioManager.MODE_NORMAL ); 

OR, you can mute the sound by changing the volume:

 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); 
+6
source

All Articles