小编Jam*_*ong的帖子

在没有BluetoothGATT的情况下断开BluetoothDevice的连接

我的应用程序与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实例似乎在我断开连接时实际上并未断开外围设备的连接。

所以我的问题是:

  • 有没有一种方法可以在不调用connectGatt的情况下断开连接的BluetoothDevice?
  • 为什么connectGatt对于已连接的设备要花费这么长时间?
  • 在连接的BluetoothDevice上调用connectGatt甚至有效吗?

谢谢

android bluetooth-lowenergy android-ble

6
推荐指数
1
解决办法
3800
查看次数

标签 统计

android ×1

android-ble ×1

bluetooth-lowenergy ×1