Android Bluetooth Headset Transition - android

How exactly does Android handle the transition to a bluetooth headset when the connection is made? With the default music application, my device stops the audio from coming out the speaker, then routes it to the headphones as soon as a connection is made. When turning off the bluetooth headset, the device immediately detects the lost connection and starts routing through the device speaker again. Is this handled by the Android OS or by the application itself?
I ask because I am working on an app that plays streams off the internet. My app only behaves as described above 50% of the time. Sometimes when connecting the bluetooth headphones the audio does not automatically switch until I stop the output and start it again. The same goes for a disconnection. The device detects that the headphones are gone, but my audio does not automatically return back through the speakers until I restart the stream.

Related

Android bluetooth microphone stops recognizing after a few seconds

I've implemented this solution to get AudioRecord working with bluetooth earpieces.
This works well until no sound is transferred to and from the bluetooth device, however if there is no sound output, and no microphone output for a few seconds, the micro
phone stops listening.
I tried to listen almost all intent actions, but I have nothing when the microphone stops.
How could I get a message on this kind of timeout, or how could I keep this connection on ?

On Android 11, audio is not playing for other apps while my app is connected to a Bluetooth speaker mic

My application allows for users to transmit and receive audio, similar to a walkie talkie. Much like a walkie talkie, there is not always audio being transmitted/received, and we handle the audio focus as appropriate. Users are able to do this using both the phones built-in speaker + mic, and Bluetooth connected devices which provide speaker or mic. On Android 11, whenever my app is active while a Bluetooth device is connected, audio from other applications does not play.
As an example, say the user is using my app with a Bluetooth speaker mic connected. They are able to correctly receive (hear) my app audio through the Bluetooth device, and transmit (speak) audio through the Bluetooth device. However, if they attempt to play audio from another app, like say a video on YouTube - the video plays but the audio does not come through; either through the Bluetooth device or the phone speaker.
This incorrect behavior is new to my app on Android 11; audio works properly on prior versions of Android. Likewise, audio works properly when there is no connected Bluetooth audio device; other app audio plays as expected through the phone speaker when my app is not receiving/transmitting audio.
In my research into this issue, it appears there are some long-standing issues with Bluetooth on Android 11, with regards to both Android Auto and audio devices generally. My app utilizes the AudioManager SCO states to determine when an audio device is connected, and I suspect that a change in Android 11 related to this area is the culprit.
I haven't found many programmatic discussions about this issue, so if anyone has any ideas or suggestions about things to try, I would be most appreciative. Thanks for your time.

Switching Bluetooth SCO (headset) device when multiple are connected

I'm working on getting bluetooth working in my app for VoIP calls, and I can get the headset connected and playing correctly.
I'm using a combination of listening for Bluetooth Headset changes as well as using the Bluetooth profile proxy to see which headsets are connected.
When I call get the proxy,
mBluetoothAdapter.getProfileProxy(context, pofileListener, BluetoothProfile.HEADSET)
https://developer.android.google.cn/reference/android/bluetooth/BluetoothAdapter#getProfileProxy(android.content.Context,%20android.bluetooth.BluetoothProfile.ServiceListener,%20int)
I get a list of the currently connected bluetooth headset devices, and it tells me which one is connected to Audio with a boolean flag
https://developer.android.google.cn/reference/android/bluetooth/BluetoothHeadset#isAudioConnected(android.bluetooth.BluetoothDevice)
I can't figure out how to change the audio source though? I want to show these two connected devices in a dialog and let the user choose between them.
I can physically turn one or the other device on/off and the audio transitions smoothly every time, I just want to let the user choose where the audio goes.

How to switch the android music output device

I'm doing some test work on android music playback. I have a headset and a bluetooth headset connect with the phone at the same time.
Then there will be 4 output devices that can play the sound: speaker, handset, headset, and the BT_headset.
What I want to know is: is there a way to switch the audio output to the 4 device using code?
I cant do switch between speaker and handset if there is no headset plugin using audioManager.setMode(). But, if a headset plugin the sound can not out from handset.
Then, if the headset and bt_headset connect at the same time, the sound always out from the later connect one.

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...

Categories

Resources