Connect to bluetooth headset in android
Asked Answered
R

1

1

I have following problem: When my headset is turned on before my phone bluetooth is on, it will not connect to my phone. It will only connect to my phone when phone bluetooth is on and my headset is turned on second. I found out that I can still connect to my headset when bluetooth is turned on second (1. case), by going into androids bluetooth menu where my paired devices are listed and select my headset (although my headset is listed as 'connected'). This will connect my headset and my phone too.

What I now want to do is to perform the second way of connecting to my headset, when my phone bluetooth is turnd on second, programatically. I want to use android version 2.0 (API Level 5), so i tried BluetoothDevice.createRfcommSocketToServiceRecord and called connect() on my socket. But I'm always getting an Exception "Connection refused" or "Service discovery failed". I have used many UUID which I thought could be the right one and have anything to do with headset.

Rebec answered 18/4, 2011 at 19:33 Comment(0)
H
3

You cannot do call the RFCOMM api to connect to the headset. It is meant to connect to the SPP profile , the Headset will use the HS/HFP Profiles. Using differnt UUIDs also on the RFCOMM apis will not solve the problem.

Basically this Headset level profile connection is done internally by Android (and there are no application level access to establish connections) Applications can only get state of the conenctions - see the BluetoothHeadset Class

the current behavior is the correct recommended behavior , i.e. the headset should connect to the Phone , so the phone should be on before the headset is turned on. It is recommended as such for good user experience and predictability, if both devices try to connect to each other randomly it will not get connected.

Herve answered 19/4, 2011 at 4:52 Comment(2)
Basically this Headset level profile connection is done internally by Android (and there are no application level access to establish connections). but in my case when i m in a sip call,gsm call answered and ended, platform fails to re-connect when i say startbtsco().from adb logs i saw bluetooth socket exception.any sol?Foam
Explained well, thanks. Although I do not agree that this implemented behavior is right in general. One reason was given in above comment, another one is, that you could have a HFP car kit (which is powered on with the car) and you could leave the BT range and come back in range - there will be no reconnect by Android nor from car kit. I think the Android implementation is way too theoretical...Fielding

© 2022 - 2024 — McMap. All rights reserved.