2

My App is making a call:

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster");
startActivity(intent);

This work fine, call starts.

For real headsets, it is ok, call starts on the headset, but for "headset-like" devices, like a smart watch (which behaves like a BT headset, and can take over the call), the call starts on the phone, and user has to press the "Headset" button manually on the call screen to move to call to the smart watch. However, I want the phone to make the call always via the headset automatically. Or that is also ok, if headset mode is toggled after call has been started (within 1-2 sec), if not possible to start immediately via the headset.

Anyone has any idea?

** UPDATE **

In a Call Broadcast Receiver, I tried (of course with all necessary permissions):

AudioManager audioManager;
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
  • audioManager.setSpeakerphoneOn(false) -> works, switches off the Speaker during the call (if it was on)
  • audioManager.setSpeakerphoneOn(true) -> works, switches on the Speaker during the call (if it was off)
  • audioManager.setBluetoothScoOn(false) -> works, switches off the BT headset during the call (if it was on)
  • audioManager.setBluetoothScoOn(true) -> DOES NOT work, does not switch on the BT headset during the call (if it is off)

I found this in the Android AudioManager::startBluetoothSco doc:

This method can be used by applications wanting to send and received audio to/from a bluetooth SCO headset while the phone is not in call.

Strange...

Thank you.

Zoli
  • 841
  • 8
  • 31
  • 1
    Your investigation states that it is not possible, I believe this was introduced due to security issues (else it would be fairly easy to capture phone calls for evil purposes) – Tobrun Dec 11 '14 at 10:48
  • It is possible, I saw one Application did it. Basically, the Call should just switch to Headset mode automatically. – Zoli Dec 11 '14 at 11:20
  • **Note:** I found that App also says it does not work anymore in 4.4 (kitkat). Maybe you will be right, it is not possible? However, Samsung factory watch app does this, it can activate the BT mode during call on the phone. Maybe it has some extra parameter to pass to ACTION_CALL. Is there any way to catch that? – Zoli Dec 15 '14 at 15:36
  • Try to check this. related to your problem. [LINK][1] [1]: http://stackoverflow.com/questions/3806536/how-to-enable-disable-bluetooth-programmatically-in-android – newb Dec 18 '14 at 08:23
  • newb: No, this is totally different. – Zoli Dec 28 '14 at 16:14

1 Answers1

2

Try to use Broadcase Receiver of call start send a broadcast and switch call to headset mode.

use following action in broadcast receiver.

for outgoing call - android.intent.action.NEW_OUTGOING_CALL

for incoming call - android.intent.action.PHONE_STATE In the you can use different states like "phone ringing","phone pickup" and etc, similar like this you can check for condition and do the appropriate code as you want in receiver method of broadcast receiver.

For transfring the call to bluetooth :

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
    telephonyManager.listen(phoneStateListener,
            PhoneStateListener.LISTEN_CALL_STATE);
}
  audioManager.setBluetoothScoOn(true);
  audioManager.startBluetoothSco();
Hardik Chauhan
  • 2,750
  • 15
  • 30
  • I am only interested in outgoing calls. But as MY APP starts the call, I know when the outgoing call happens, no need for broadcast receiver. You wrote: _switch call to headset mode._ **This is my question, how can I do that**? Thx – Zoli Dec 12 '14 at 23:35
  • Ok, my app just initiates the call, so I could still need broadcast receiver to catch the exact moment, but still, the question, how to **switch call to headset mode** ? – Zoli Dec 13 '14 at 15:24
  • Thanks your update. But see my comment about **startBluetoothSco();** in the question. – Zoli Dec 14 '14 at 18:14
  • Did you give this permission, Requires Permission: MODIFY_AUDIO_SETTINGS. – Hardik Chauhan Dec 15 '14 at 04:44
  • Sure. But it seems, this is done by purpose, as the android doc says: _This method can be used by applications wanting to send and received audio to/from a bluetooth SCO headset while the phone is not in call._ I tried in 4.4.4. – Zoli Dec 15 '14 at 15:20