Android:BLE 清除取消自动连接

问题描述

在我的应用程序中,我使用自动连接来连接可用的 BLE 设备。

如何在需要时取消自动连接

我的自动连接代码

bluetoothAdapter.getRemoteDevice(macAddress).connectGatt(this,true,callBack)

如何取消?

解决方法

您只需在返回的 BluetoothGatt 对象上调用 disconnect() 即可。

如果您不再需要 BluetoothGatt 对象,请调用 close() 以释放蓝牙堆栈中的资源。