how to make a phone call with speaker on

2019-02-18 05:25发布

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

2条回答
Anthone
2楼-- · 2019-02-18 05:36

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

查看更多
smile是对你的礼貌
3楼-- · 2019-02-18 05:42

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); 
查看更多
登录 后发表回答