android - 如何使用 Android 订阅多个 BluetoothLE 特性

标签 android bluetooth-lowenergy characteristics

我正在开发一个 Android 应用程序,它应该订阅多个 BLE 特性。

但无论我做什么,我都只会收到一个特征的更新值。

这是代码:

BluetoothGattCharacteristic characteristicVel = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.VELOCITY);
                gatt.setCharacteristicNotification(characteristicVel, true);
                BluetoothGattDescriptor descriptorVel = characteristicVel.getDescriptor(
                        BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
                descriptorVel.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
                gatt.writeDescriptor(descriptorVel);

            BluetoothGattCharacteristic characteristicAcc = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.ACCELERATION);
            gatt.setCharacteristicNotification(characteristicAcc, true);
            BluetoothGattDescriptor descriptorAcc = characteristicAcc.getDescriptor(
                    BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
            descriptorAcc.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descriptorAcc);

无论我做什么,我都只能得到速度数据。如果我更改两个 block 的顺序,我只会获得加速度,但不会获得更多速度数据。

我需要做什么才能同时订阅多个特性?

提前致谢

雷托

最佳答案

要让描述符依次写入,请等待描述符写入的回调,然后再开始下一个描述符。

关于android - 如何使用 Android 订阅多个 BluetoothLE 特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38230684/

相关文章:

Android alertdialog 如何在我从单选项目中选择项目后防止否定按钮确认操作

java - Android BLE 中未调用 onBatchScanResults

ios - 如何从 Swift 中的蓝牙特性中获取数据

swift - 数据是否写入BLE 写入后返回特性

android - PANIC : Cannot find AVD system path. 请定义 ANDROID_SDK_ROOT

android - StringBuilder 似乎超出了容量

ios - 如何在 iOS swift 中使用多个属性初始化 CBMutableCharacteristic

更改 UUID 后,Android 蓝牙未发现该特性

android - 如何避免在 AdMob 的 XML 中复制/粘贴 adUnitId?用于测试和发布

bluetooth-lowenergy - BLE 通告是否需要提供非空本地名称?