如何断开但不会取消配对已配对的Android蓝牙耳机

问题描述

我通过了HeadphoneConnectThread的蓝牙设备,即索尼WH-1000XM3。

HeadphoneConnectThread类尝试与蓝牙耳机建立连接。

连接部分工作正常,即已连接配对的耳机,并且可以将数据流式传输到其中。

要断开连接,我打电话给Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();,它更新了close()的状态(见下文),但是耳机没有断开连接。

BluetoothSocket

债券状态12:

https://developer.android.com/reference/android/bluetooth/BluetoothDevice#BOND_BONDED


socket.isConnected()=false,headphone.getBondState()=12

解决方法

从您链接的文档中:

Being bonded (paired) with a remote device does not necessarily mean the device is currently connected. It just means that the pending procedure was completed at some earlier time,and the link key is still stored locally,ready to use on the next connection.

因此,如果您的代码输出socket.isConnected = falsebondedState=12,则仅表示它们已配对并断开连接。

您的代码没有错误。