Android startBluetoothSco() not interrupted by incoming call - android

I've managed to get text-to-speech audio streaming through my SCO headset using startBluetoothSco(), but it's not interrupted by incoming phone calls, as documented at http://developer.android.com/reference/android/media/AudioManager.html:
Note that the phone application always has the priority on the usage of the SCO connection for telephony. If this method is called while the phone is in call it will be ignored. Similarly, if a call is received or sent while an application is using the SCO connection, the connection will be lost for the application and NOT returned automatically when the call ends.
When a call comes in, I can hear both the phone call audio and my text-to-speech audio at the same time. Has anyone successfully gotten the correct behavior with incoming phone calls? I'm testing on a Samsung Captivate running Android 2.2. Thanks!

What stream are you using? Make sure you are not using VOICE_CALL stream.

Related

Android bluetooth sco not picking headset microphone after pairing

I'm trying to correctly setup bluetooth SCO in my app. After many attempts it seems that I've found a way to enable it "almost" reliably, in the sense that it works almost always, but in one case: if I launch my app and AFTER this I pair the headset, the headset mic is not picked (the phone mic is picked instead), while the headset earphones are correctly picked.
If instead I pair the headset BEFORE launching the app, everything seems to work fine.
The strange thing is that, even when the phone mic is picked, calling getRoutedDevice() on my AudioRecord object returns the bluetooth headset.
I tried to use SetPreferredDevice on the AudioRecord object, but apparently it has no effect.
The only way I found to ALWAYS pick the headset microphone is to call
audioManager.setMode(AudioManager.MODE_NORMAL);
However in this case, the output comes from the phone speaker and not from the BT headset earphones!
If instead i call:
audioManager.setMode(AudioManager.MODE_IN_CALL);
the output comes consistently (and correctly) from the BT headset earphones, but I have the above mentioned mic issue (pairing the headset after launching the app, the phone mic is picked instead of the BT headset one).
The sequence I am using is:
I have a thread that checks if a bluetooth headset is connected and works pretty much reliably.
When isHeadsetConnected is true I do:
arec.stop(); // my AudioRecord object
atrack.stop(); // my AudioTrack object
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.startBluetoothSco();
In the listener of AudioManager.EXTRA_SCO_AUDIO_STATE, when I receive SCO_AUDIO_STATE_CONNECTED) I do:
audioManager.setBluetoothScoOn(true);
atrack.play();
arec.startRecording();
After struggling a lot, this seems to be the "almost" perfect sequence, with the caveat that it does not work fully if the first pairing is made with the application running.
I've made an attempt to pair the same headset during a Whatsapp call, and the bluetooth headset starts without any problem both input and output, so THERE MUST be a way to accomplish this!
I have read tons of questions/answers but none of these seems to consistently solve my problem.
I am using Android 11 on a CAT S62 Pro.

Android audio over HSF bluetooth connection using a virtual call

I'm trying to send audio over my cars speakers without having the cars audio input set to bluetooth. It supports the A2DP profile, and I also managed to get it to work. But that only works when I manually set the input to Bluetooth.
But I would like to 'force' the audio being sent over the speakers.
I previously had an iPhone. The Google Maps app would 'call' itself everything it would pronounce the directions. So my car would see it is an incoming call and play the audio over the speakers.
I looked around the internet, and it seems I need to use the HSF profile to pull of the same trick.
The documentation states that HSF is supported, but it does not show me how to do it. I also found exactly what I needed in the documentation. It states the following:
NOTE: up to and including API version JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO audio connection is established.
So initiating virtual voice calls was possible. I would like to know how to do that now. Any other ideas on how to do this would also be very helpfull.

Get voice stream during android call

I have wifi connection between java desktop app and android app. I need to transfer opponent's voice during call to desktop side and also transer my voice from desktop's microphone to opponent. How can I do it? How can I get input and output streams of call?
You can not handle gsm call data (neither send over uplink nor receive over downlink). I think you can try sip calls if that meets your requirement.

How call process works with blue tooth devices?

I tested few things on Android mobiles with bluetooth headset.I have few questions regarding the same.
Device Specifications :
Android 2.3 above
Headset Blue tooth profiles : HFP,A2DP
I accepted a call from accept button from the android mobile and I was able to hear the call from the bluetooth headset.After that I moved android device out of range and accepted the call from android and when the android mobile entered bluetooth range bluetooth headset connected automatically.Is it universal, I mean all the bluetooth headsets support the same or are there any deviations?
I would like to know what will happen when we accept the call from headset or Android mobile.Is it something like Android OS is going to create a call session/audio session and transfer this to headset when accept button is pressed from the headset.If a call is already received and when the headset is in bluetooth range,Android mobile is going to route the volume to headset. In both the cases the same thing happens(just routing the audio).I would like to know the call handling in detail both the cases.Could some one help me on this.
How the call process is different in iOS?
Edit
Is any call session like AVAudoioSession is getting created when we accept a call ?
#jjv360:
"An app can manually assign a route even though a bluetooth headset is connected, in which case it's up to the app to handle what happens when a new route is detected..."
Is it possible to route the call session to headset(from microphone to headset sco) in an iOS app?Could you please give some pointers on this.
On iOS if you connect a bluetooth headset while an audio session is active the current audio app(s) get notified and by default will transfer the session's route to the headset. An app can manually assign a route even though a bluetooth headset is connected, in which case it's up to the app to handle what happens when a new route is detected...
Also, AFAIK the reconnect is attempted by both the device (for a very short time) and the headsets, so it's mainly up to the headset to attempt reconnecting when it goes out of range. Almost all headsets should do this though.
It doesn't matter which button was used to accept the call (on device or on headset), if the bluetooth headset is connected it will be used, unless an app has specified that it doesn't want to use that route.
The call process AFAIK is the same for Android and iOS.
With the protocol used, A2DP is the high-quality protocol used when listening to music. It supports high-quality audio, but is one-way, so only works if the bluetooth headset is not recording from the mic. HFP is used when recording is also needed, but the quality is less. That is why you will notice on iOS if you're listening to music on bluetooth headset and then start a recording app, the sound quality will become worse until you stop the recording...

Android bluetooth SCO

I faced problem with bluetooth SCO audio in my android app.
I registered a receiver for actions ACL_CONNECTED and ACL_DISCONNECTED to capture the bluetooth SCO device connection and disconnection. On receive of ACL_CONNECTED I am checking whether bluetooth device has Audio service (headset) or not, if has AUDIO service, I am instantiating AudioTrack (new AudioTrack(....)) and starting bluetooth SCO (startBluetoothSco(); setBluetoothScoOn(true);).
I have a button in my app to write pcm data to AudioTrack. In this app I am not able to hear sound of PCM data i written.
I tried without any receiver and in onCreate() only I instantiated AudioTrack and started bluetooth SCO. Before launching app, I connected headset to my device and tested, it is working fine.
But, why my app is not working when established bluetooth SCO connection at run-time depending on ACL_CONNECTED intent.
If anybody know the solution please reply me. I added all required permissions BLUETOOTH, BLUETOOTH_ADMIN, MODIFY_AUDIO_SETTINGS (don't report about spelling mistakes in these permissions).
Using what version API?
When creating your receiver use BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED instead of ACL_CONNECTED.
intentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); // API 11
intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED); // API 8
intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); // API 14

Categories

Resources