I'm working on BLE devices whose address I know.
Before reading a characteristic, I'd like to test if the device isn't already connected.
Seem's it has to be done throught BluetoothManager.getConnectedDevices()
So I wrote a little isConnected() method:
fun isConnected(address: String): Boolean {
val connDev = bluetoothLEHandler.bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)
connDev.forEach{ if(it.address == address ) return true }
return false
}
在判断现有连接后,如果答案是肯定的,我想使用相应的GATT:
if(isConnected(device.address)){//don't reconnect, just trigger connection callback
onConnectionEstablished(/*here I need the gatt of the already connected device*/)
}
- 我如何才能获得GATT,知道设备,并知道此设备已连接?
->;或者我正在try 做一些愚蠢的事情,我应该总是使用device.connectGatt(...)
来获得GATT,甚至不try 判断是否还没有连接吗?
- 或者这种情况应该永远不会发生,因为我应该总是关闭以前的连接,即使知道我有很高的可能性必须立即重新连接?