2

I have a service that start a call when something happened, that works prefect but my question is how can I start it with speaker on?(and remove the speaker after 2 min?)


according to your all anwsers,

this code should work -

                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + num));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_FROM_BACKGROUND);// (i'm starting the call from service..)
                startActivity(intent); //the call start here, work perfect
                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                audioManager.setMode(AudioManager.MODE_IN_CALL);
                audioManager.setSpeakerphoneOn(true);

well, It doesnt work.. why?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Didi78
  • 247
  • 1
  • 15
  • possible duplicate of [how to make a phone call with speaker on](http://stackoverflow.com/questions/8791754/how-to-make-a-phone-call-with-speaker-on) – xenteros Jun 01 '15 at 10:29

2 Answers2

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

Use this to turn speaker on once call is picked up.

Premission

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Register PhoneStateListener to know when call is picked up. urn speaker on when call state is TelephonyManager.CALL_STATE_OFFHOOK

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(false);
audioManager.setMode(AudioManager.MODE_NORMAL);
0

Use an AudioManager to turn on the speakers and a CallStateListener for checking if the call is over. If is not, check if it lasts two minutes.

xenteros
  • 15,586
  • 12
  • 56
  • 91