简体   繁体   English

连接到Android中的蓝牙耳机

[英]Connect to bluetooth headset in android

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'). 我发现进入蓝牙第二秒钟(1种情况)后,仍然可以连接到我的耳机,方法是进入android蓝牙菜单,其中列出了我的配对设备并选择了我的耳机(尽管我的耳机列为“已连接”) 。 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. 我想使用Android 2.0版(API级别5),所以我尝试了BluetoothDevice.createRfcommSocketToServiceRecord并在我的套接字上调用了connect() 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. 我使用了许多UUID,我认为这是正确的选择,并且与耳机有关。

You cannot do call the RFCOMM api to connect to the headset. 您无法调用RFCOMM api连接到耳机。 It is meant to connect to the SPP profile , the Headset will use the HS/HFP Profiles. 它旨在连接到SPP配置文件,耳机将使用HS / HFP配置文件。 Using differnt UUIDs also on the RFCOMM apis will not solve the problem. 在RFCOMM api上也使用不同的UUID将无法解决问题。

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 基本上,此耳机级别配置文件连接由Android内部完成(并且没有应用程序级别访问权限来建立连接)应用程序只能获取连接状态-请参阅BluetoothHeadset

the current behavior is the correct recommended behavior , ie the headset should connect to the Phone , so the phone should be on before the headset is turned on. 当前行为是正确的建议行为,即耳机应连接到Phone,因此应在耳机打开之前打开手机。 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. 因此,建议这样做是为了获得良好的用户体验和可预测性,如果两个设备尝试随机相互连接,将无法连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM