Android 为什么配对后我会收到ACTION\u ACL\u DISCONNECTED

Android 为什么配对后我会收到ACTION\u ACL\u DISCONNECTED,android,bluetooth,android-bluetooth,Android,Bluetooth,Android Bluetooth,对于Android,我用一个服务编写了一些代码,该服务在执行时会查找我的BT设备,并调用device.createrFComSocketToServiceRecord查找它找到的配对设备(目前只有一个)。这很有效 出于测试目的,在服务运行时,我会手动取消配对,然后再次配对。当我这样做时,我会进行配对和连接,但随后我会收到操作ACL\u DISCONNECTED 简而言之,它看起来是这样的: 配对时,我得到以下信息: I/MainService﹕ Entering Service bcrcvrBl

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

出于测试目的,在服务运行时,我会手动取消配对,然后再次配对。当我这样做时,我会进行配对和连接,但随后我会收到操作ACL\u 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
然后是时候输入pin了。之后,我看到以下情况:

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_之前,一切看起来都很好。这会让我的代码处理一个设备被移除的情况。如果我能缩小搜索范围,我很乐意发布一些代码

为什么配对后我会收到ACL\U断开连接

编辑:


对于任何可能犯我犯过的同样愚蠢错误的人。事实证明,在我收到操作\u BOND\u STATE\u更改为BOND\u BOND之前,我正在尝试创建BT套接字。这似乎导致了ACL断开连接的操作。我本以为在这种情况下会有错误,但我想不会。问题解决了

只需再加一句评论。您所描述的内容不仅适用于RFCOMM,也适用于A2DP。注意方法createBond()并不总是进行bond和profile连接(这取决于硬件,我已经用不同的方法进行了测试)

因此,正确的方法是调用createBond(),等待BOND_BONDED事件,然后连接到A2DP代理。A2DP_连接事件后,该信号可靠