配对后为什么我会收到ACTION_ACL_DISCONNECTED

时间:2015-01-30 03:00:10

标签: android bluetooth android-bluetooth

对于Android,我已经用一项服务编写了一些代码,在执行时,该服务会查找我的BT设备,并为它找到的配对设备调用device.createRfcommSocketToServiceRecord(目前只有一个)。这很有效。

出于测试目的,在服务运行时,我手动取消配对,然后再次配对。当我这样做时,我得到配对并连接,但后来我收到了ACTION_ACL_DISCONNECTED。

简而言之,它看起来像这样:

当我配对时,我得到以下内容:

I/MainService﹕ Entering Service bcrcvrBluetooth bcReceiver: Action = android.bluetooth.device.action.BOND_STATE_CHANGED
I/MainService﹕ Service bcrcvrBluetooth: action = BluetoothDevice.ACTION_BOND_STATE_CHANGED
I/MainService﹕ Prev State: BluetoothDevice.BOND_NONE
I/MainService﹕ New State: BluetoothDevice.BOND_BONDING

然后是时候输入引脚了。之后,我看到以下内容:

I/MainService﹕ Entering Service bcrcvrBluetooth bcReceiver: Action = android.bluetooth.device.action.ACL_CONNECTED
I/MainService﹕ Service bcrcvrBluetooth: action = BluetoothDevice.ACTION_ACL_CONNECTED

I/BTDevice﹕ Creating socket
I/BTDevice﹕ Device socket created

I/MainService﹕ Entering Service bcrcvrBluetooth bcReceiver: Action = android.bluetooth.device.action.BOND_STATE_CHANGED
I/MainService﹕ Service bcrcvrBluetooth: action = BluetoothDevice.ACTION_BOND_STATE_CHANGED
I/MainService﹕ Prev State: BluetoothDevice.BOND_BONDING
I/MainService﹕ New State: BluetoothDevice.BOND_BONDED
I/MainService﹕ Device Paired.

I/MainService﹕ Entering Service bcrcvrBluetooth bcReceiver: Action = android.bluetooth.device.action.ACL_DISCONNECTED
I/MainService﹕ Service bcrcvrBluetooth: action = BluetoothDevice.ACTION_ACL_DISCONNECTED

理想情况下,我会提供一些代码来提供帮助;但是,它分散在多个类,线程等中......简短的版本是一切看起来都很棒,直到我收到ACL_DISCONNECTED由于某种未知原因。这会抛出我的代码来处理已删除设备的情况。如果我可以缩小搜索范围,我会很乐意发布一些代码。

配对后为什么会收到ACL_DISCONNECTED?

编辑:

对于其他可能犯同样愚蠢错误的人我做了。事实证明,在我收到带有BOND_BONDED的ACTION_BOND_STATE_CHANGED之前,我试图创建BT套接字。这似乎导致了ACTION_ACL_DISCONNECTED。我本来期望在这种情况下出错,但我猜不是。问题解决了

1 个答案:

答案 0 :(得分:0)

再发表一条评论。您所描述的内容不仅对RFCOMM有效,而且对A2DP也有效。请注意,方法createBond()始终不能建立绑定和配置文件连接(取决于硬件,我已经用不同的方法进行测试了)

因此,正确的方法是调用createBond(),等待BOND_BONDED事件,然后建立与A2DP代理的连接。 A2DP_CONNECTED事件发生后,连接可靠