连接到蓝牙耳机的android [英] Connect to bluetooth headset in android

查看:348
本文介绍了连接到蓝牙耳机的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:
当我的耳机已在之前我的手机蓝牙打开时,它不会连接到我的手机上。当手机蓝牙功能,而且我在耳机开启第二,它只能连接到我的手机上。我发现我仍然可以连接到我的耳机时,蓝牙开启第二个(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.

我现在想要做的是执行连接到我的耳机,当我的手机蓝牙是turnd在第二,编程的第二种方式。我想使用Android 2.0版本(API等级5级),所以我尝试 BluetoothDevice.createRfcommSocketToServiceRecord 键,名为连接()在我的插座。但是,我总是得到一个异常连接被拒绝或服务发现失败。我已经使用了许多UUID,我认为可能是正确的,有什么用耳机。

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.

推荐答案

您不能做叫RFCOMM API连接到耳机。是指连接到SPP轮廓,耳机将使用的HS / HFP概况。使用UUID的不同的充也对RFCOMM的API将是不能解决问题的。

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.

基本上这个级别耳机连接配置文件在内部由Android进行(且没有应用程序级别的访问来建立连接)的应用程序只能拿到conenctions的状态 - 看的 BluetoothHeadset

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

目前的行为是正确的推荐行为,即耳机应该连接到手机,所以手机应该在耳机开启之前。它被推荐为这种良好的用户体验和predictability,如果两个设备尝试连接到彼此随机它不会连接。

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.

这篇关于连接到蓝牙耳机的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆