[英]How to know if BLE device is connected currently
Is there any method like device.isConnected() to know the present state of android BLE device . 有没有像device.isConnected()这样的方法来了解android BLE设备的当前状态。 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.
我所知道的是我需要实现一些类似GattclientCallBack类接口的体系结构,以了解设备是否已连接,但我找不到这样的方法。 Also the method
也是方法
mBluetoothGatt.getConnectionState(device);
returns int . 返回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. getConnectionState
返回的int
将分别为0,1,2或3,分别对应于STATE_DISCONNECTED
, STATE_CONNECTING
, STATE_CONNECTED
或STATE_DISCONNECTING
。 See the docs for more information. 有关更多信息,请参阅文档 。 Note that this method is only available on API level 18 and higher.
请注意,此方法仅适用于API级别18及更高级别。
However, the documentation of this method includes the following warning: 但是,此方法的文档包括以下警告:
Not supported - please use
getConnectedDevices(int)
withGATT
as argument不支持 - 请使用带有
GATT
getConnectedDevices(int)
作为参数
This refers to the method BluetoothManager.getConnectedDevices
. 这是指
BluetoothManager.getConnectedDevices
方法。 The constant value to pass is BluetoothProfile.GATT
. 要传递的常量值是
BluetoothProfile.GATT
。 Again, this method is only available on API level 18 and higher. 同样,此方法仅适用于API级别18及更高级别。 It sounds like this method will be perfect for your use-case.
听起来这种方法非常适合您的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.