Is there any method like device.isConnected() to know the present state of android BLE device . What I know is I need to implement some architecture like interface from GattclientCallBack class to know if device is connected,but I don't find any method like this. Also the method
mBluetoothGatt.getConnectionState(device);
returns int . So exactly how do I know if device is connected ? Thanks :)
The int
returned by getConnectionState
will be 0, 1, 2, or 3, corresponding to STATE_DISCONNECTED
, STATE_CONNECTING
, STATE_CONNECTED
, or STATE_DISCONNECTING
respectively. See the docs for more information. Note that this method is only available on API level 18 and higher.
However, the documentation of this method includes the following warning:
Not supported - please use
getConnectedDevices(int)
withGATT
as argument
This refers to the method BluetoothManager.getConnectedDevices
. The constant value to pass is BluetoothProfile.GATT
. Again, this method is only available on API level 18 and higher. It sounds like this method will be perfect for your use-case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With