与设备断开连接时,我是否也应该得到 BluetoothGatt.GATT_SUCCESS?

Should I get BluetoothGatt.GATT_SUCCESS also when disconnecting from a device?

我正在使用自定义设备,我正在努力正确管理蓝牙 LE。

我唯一担心的是当我读取 status 值以及 newState 变量(什么意思是 BluetoothProfile.STATE_DISCONNECTED)上的值 2 时没有得到 0 (BluetoothGatt.GATT_SUCCESS)方法onConnectionStateChange。相反,我得到了 8,在 BluetoothGattBluetoothProfile 类.

中无法跟踪的内容

所有连接工作正常,我完美地读取和写入值。

(1) 应该是这样吗?为什么我读八?

我在 onConnectionStateChange 方法中看到了许多 status 值:8、19、133 等

(2) 我在哪里可以查看这个值?

提前致谢


编辑api.h 文件中有很多值,我们找错了地方。

8: 0x08 = GATT CONN TIMEOUT 19: 0x13 = GATT CONN TERMINATE PEER USER 133: 0x85 = GATT_ERROR

int 错误代码需要转换为 HEX 并映射到以下文件中的值:

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.1_r13/stack/include/gatt_api.h

在您提到的情况下:

8 = GATT_INSUF_AUTHORIZATION
19 = GATT_RSP_WRITE 
133 = GATT_ERROR

答案是否定的。

我没有收到 BluetoothGatt.GATT_SUCCESS,因为连接已被另一端关闭。如果执行 gatt.disconnect() 我读 status = BluetoothGatt.GATT_SUCCESS.