0
AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

We have this code to do a video call on Speaker. If user connects earphones, then we we are checking using the below code.

if(audioManager.isWiredHeadsetOn()) {
    audioManager.setWiredHeadsetOn(true);
} else {
    audioManager.setSpeakerphoneOn(true);
}

But the above code detects headset but audio is still on speaker rather than in earphones. How to fix this ?

And i want to know how to handle if user connects headset during a call. How to detect and send Audio through earphones at that time ?

Woona
  • 15
  • 6
  • https://stackoverflow.com/questions/31397934/how-to-play-audio-through-speaker-even-when-headset-is-plugged-in – Mapsy Aug 03 '17 at 14:55
  • I am asking audio through earphones rather than speaker. – Woona Aug 03 '17 at 14:59
  • Looked like he had the reverse problem to you. There might be something to gain by checking the differences in implementation. – Mapsy Aug 03 '17 at 15:00

1 Answers1

0

We need to set the speaker to "false" before setting the wired headset "true"

if(audioManager.isWiredHeadsetOn()) {
    audioManager.setSpeakerphoneOn(false);
    audioManager.setWiredHeadsetOn(true);
} else {
    audioManager.setSpeakerphoneOn(true);
}
Woona
  • 15
  • 6