Elad Gelman
Elad Gelman

Reputation: 1182

how to make a phone call with speaker on

brought here is the code for making 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 is:

how can I make the phone call and turn the speaker on?

10X Elad

Upvotes: 5

Views: 9901

Answers (2)

ksu
ksu

Reputation: 902

I found out that if I add the code in this following order works best for me

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

whereas the following not work for me if I setSpeakerphoneOn(true) at the first line:

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

Upvotes: -2

Force
Force

Reputation: 6392

Use an AudioManager to turn on the speakers and a CallStateListener for receiving the end of the call.

Upvotes: 6

Related Questions