gpt4 book ai didi

Android BLE Gatt 连接更改状态

转载 作者:太空狗 更新时间:2023-10-29 15:33:10 26 4
gpt4 key购买 nike

我有一个 Android 应用程序可以连接到 BLE 设备并向其写入数据。我可以成功连接、读取和写入它。作为测试的一部分,我们正在尝试不同的断开连接场景。

有时,如果 BLE 设备断开连接,我将连接更改为断开连接,状态值为 19。此外,如果有任何绑定(bind)错误,状态等于 22。如果我以编程方式断开连接,则此状态为 0。但除 0 外,这些状态均未在 android documentation 中指定。 .

发布示例 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 possible 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)

我已经在 5.0.2、5.1、6.0 和 6.0.1 中测试了断开连接的情况。但是在6.0.1 android版本才发现这个债券发行代码。

关于Android BLE Gatt 连接更改状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45056566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com