Jam*_*ong 6 android bluetooth-lowenergy android-ble
我的应用程序与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实例似乎在我断开连接时实际上并未断开外围设备的连接。
所以我的问题是:
谢谢
这是我的2美分,供您查询。
有没有一种方法可以在不
调用connectGatt的情况下断开连接的BluetoothDevice ?
您需要致电,bluetoothGatt.disconnect();为什么需要致电connectGatt断开连接?如果是因为您需要gatt实例,则在设备已连接时将其保存。不要在connectedDevice上调用connectGatt。
为什么connectGatt对于已
连接的设备要花费这么长时间?
导致建立连接时,两个设备都必须处于可连接模式(有广告,可连接,不可连接等模式)。建立连接后,设备将不再处于可连接模式。那就是它需要更长的时间的原因。请勿呼叫它,或在重新连接之前断开连接。
在连接的
BluetoothDevice 上调用connectGatt甚至有效吗?
编码中的所有内容都是合法合法的,但请阅读我对第二点的回答。
| 归档时间: |
|
| 查看次数: |
3800 次 |
| 最近记录: |