我的应用程序与BLE外设通信。有时,应用程序是在已连接外围设备的情况下启动的。我可以通过调用以下方式检索设备:
BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
List<BluetoothDevice> connectedDevices = manager.getConnectedDevices(BluetoothProfile.GATT);
Run Code Online (Sandbox Code Playgroud)
然后,我可以根据地址或UUID过滤connectedDevices。但是,BluetoothDevice没有断开连接的方法。要断开连接,我需要一个BluetoothGATT实例。但是我看到的获取BluetoothGATT实例的唯一方法是调用
connectedDevice.connectGatt(Context, boolean, BluetoothGattCallback)
Run Code Online (Sandbox Code Playgroud)
这需要很长时间。最重要的是,我在调用connectGatt之后返回的BluetoothGatt实例似乎在我断开连接时实际上并未断开外围设备的连接。
所以我的问题是:
谢谢