How to make a phone call with speaker on

here is the code to make a phone call from my activity

public void makeAPhoneCallWithSpeakerOn()
{
  String uri = "tel:" + posted_by.trim() ;
  Intent intent = new Intent(Intent.ACTION_CALL);
  intent.setData(Uri.parse(uri));
  startActivity(intent); 
}

question:

how can i call and turn on the speaker?

10X Elad

+5
source share
2 answers

Use AudioManager to turn on speakers and CallStateListener to get the end of a call.

+7
source

I found out that if I add code in this next order, it works best for me

      audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
      audioManager.setMode(AudioManager.MODE_IN_CALL); 
      audioManager.setSpeakerphoneOn(true);

whereas the following does not work for me if I set SpeakerphoneOn (true) in the first line:

       audioManager.setSpeakerphoneOn(true);
       audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
       audioManager.setMode(AudioManager.MODE_IN_CALL); 
-1
source

All Articles