This question has been asked and answered twice before on this site, but that code doesn't seem to work on modern phones at all. I'm working on an Android 4.2 and an Android 4.3 and neither seems to work.
I am playing an MP3 through a Media Player during the call, and it works fine, but both the song and the call are coming through the voice speaker. If I press "Speaker" they both continue playing through the loudspeaker. I need that effect, but without having to press it myself
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
This was suggested as a solution to both other questions on S.O, but it simply doesn't work. It should, the code is fine, but it simply does nothing to the audio at all.
Thoughts?
I solved it. I created a thread that constantly runs the above three lines of code in a "While (true)". Works great.