Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable the Android speaker during a call, from code?

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?

like image 837
Viktor Zafirovski Avatar asked Nov 19 '15 04:11

Viktor Zafirovski


People also ask

How do I turn on speaker phone call?

Helpful answers. If when on a call you can only see the number dialer screen, Tap the "Hide" text at the bottom right corner of the screen to return to the phone options. Then Tap the Speaker icon to turn on the Speakerphone.

Why can't I put my Android phone on speaker?

If your Android loudspeaker won't work, restart the device and check for updates. Additionally, reset the sound settings, and disable Bluetooth and Do Not Disturb mode. If the issue persists, remove the case, clean your speaker grills, enter Safe Mode, and reset your settings.

Why is my phone call speaker not working?

Head into Settings > Connected devices to see if your phone is connected to any Bluetooth audio outputs. After this, you should head into the Sound section of Settings and confirm you haven't accidentally switched on the Do Not Disturb or Silent modes.


1 Answers

I solved it. I created a thread that constantly runs the above three lines of code in a "While (true)". Works great.

like image 106
Viktor Zafirovski Avatar answered Oct 13 '22 22:10

Viktor Zafirovski