2

I am searching a work-around for my problem specified in this question:

How to disable the wired headset programmatically in Java

As mentioned there, I am getting audio in both my speakers and headphones.

Can someone please tell me how to mute the audio in the headset programmatically, while letting it play undiminished on speaker?

Community
  • 1
  • 1
SoulRayder
  • 5,072
  • 6
  • 47
  • 93

2 Answers2

3
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(true);

And then play the sound through the AudioManager.STREAM_SYSTEM stream.

When the sound's finished playing be sure to return the audio manager to its previous state or it'll stay on loudspeaker!!

noelicus
  • 14,468
  • 3
  • 92
  • 111
  • Thanks a lot for the reply. Couple of questions though. How did you set it back to normal? *And then play the sound through the AudioManager.STREAM_SYSTEM stream.*- What specific command did you use for this? – SoulRayder Jan 08 '14 at 03:39
  • I figured it out. Thanks a ton for the answer :) Will contact you if any further queries from this post. Thanks again :) – SoulRayder Jan 08 '14 at 05:52
0

AudioManager mAudioMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mAudioMgr.setSpeakerphoneOn(true); mAudioMgr.setMode(AudioManager.MODE_IN_COMMUNICATION);

Jatinkumar Patel
  • 1,094
  • 2
  • 17
  • 34