问题描述
我有一个Android应用程序可以连接到BLE设备并对其进行写入。我可以成功连接,读取和写入它。作为测试的一部分,我们正在尝试不同的断开连接方案。
I have an android app to connect to a BLE device and write to it. I can successfully connect, read and write to it. As a part of testing, we are trying different disconnection scenarions.
有时,如果设备断开连接,我会得到连接更改为 disconnect,状态值为19。此外,如果存在任何绑定错误,则状态等于22。我以编程方式断开了连接,此状态给了我0。但是在。
Sometimes, if ble device disconnect the connection, i get the connection change as disconnect with status value as 19. Also if there is any bond error, status equals 22. If i programmatically disconnect the connection, this status gives me 0. But none of these states except 0 are specified in android documentation.
发布示例BluetoothGattCallback
Posting a sample BluetoothGattCallback
private BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.i(TAG, "onConnectionStateChange status: "+status+", newState: "+newState);
/*i need to know the posiible values for this status variable*/
if(newState == BluetoothProfile.STATE_CONNECTED) {
gatt.discoverServices();
} else {
gatt.close();
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.i(TAG, "onServicesDiscovered service discovered");
}
};
是否有人遇到过同样的问题并整理了状态列表。我需要知道onConnectionStateChange方法中状态变量的可能值
推荐答案
这是我拥有的代码列表
- 以编程方式断开连接-0
- 设备超出范围-8
- 已通过设备断开连接-19
- 有绑定的问题-22
- 未找到设备-133(某些电话可显示62)
- Programmatically disconnected - 0
- Device went out of range - 8
- Disconnected by device - 19
- Issue with bond - 22
- Device not found - 133(some phone it gives 62)
我已经在5.0.2、5.1、6.0和6.0.1中测试了断开连接的情况。但是只有在6.0.1安卓版本中才发现了这种债券发行代码。
I have tested disconnect scenario's in 5.0.2, 5.1, 6.0 and 6.0.1. But only found this bond issue code in 6.0.1 android version.
这篇关于Android BLE Gatt连接更改状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!