Android WebView and audio output on earpiece

Viewed 377

How can I force an Android WebView which loads a webrtc page to use the "earpiece" as default audio output instead of the loudspeaker?

I tried this code, but the sound keeps coming out of the speakers, not the earpiece:

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(false);

I also tried to change the second line to:

audioManager.setMode(AudioManager.MODE_IN_CALL);

Of course, I have this in the manifest file:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

I also tried this other code as suggested elsewhere:

this.player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);

None of these solutions send the sound out the earpiece.

What is the correct way to use the earpiece in case of a WebView?

Thanks

0 Answers
Related