繁体   English   中英

未调用 BLE Gatt onCharacteristicChanged 方法

[英]BLE Gatt onCharacteristicChanged method not called

我们正面临 BLE Gatt onCharacteristicChanged 方法的问题。 不调用此方法。

我们已使用以下代码启用通知:

mBluetoothGatt!!.setCharacteristicNotification("NOTIFY_SERVICE_CHARACTERISTIC", true)

val descriptor = NOTIFY_SERVICE_CHARACTERISTIC.getDescriptor(convertFromInteger(0x2902))
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
descriptor.value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
var status = mBluetoothGatt!!.writeDescriptor(descriptor)

在此之后,我们从 onDescriptorWrite 方法向 BLE 发送代码。

{WRITE_SERVICE_CHARACTERISTIC}.setValue({BYTE_ARRAY}) 
val status = mBluetoothGatt!!.writeCharacteristic(RxChar)

将代码发送到 BLE 后。 它将在 onCharacteristicWrite 方法中响应。 但是我们没有通过通知服务在 onCharacteristicChanged 方法中得到任何响应。

相同的命令在其他 BLE 扫描仪应用程序中工作,但我的应用程序面临问题。

请帮助我们解决问题。

谢谢

您正在使用指示设置覆盖描述符的通知设置:

descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
descriptor.value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE

您可能只需要通知并且可以取消启用指示:

mBluetoothGatt!!.setCharacteristicNotification("NOTIFY_SERVICE_CHARACTERISTIC", true)

val descriptor = NOTIFY_SERVICE_CHARACTERISTIC.getDescriptor(convertFromInteger(0x2902))
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
var status = mBluetoothGatt!!.writeDescriptor(descriptor)

如果您确实需要通知和指示,则必须设置如下值:

descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE | BluetoothGattDescriptor.ENABLE_INDICATION_VALUE

| 运算符执行按位或运算,因此将两个标志合并为一个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM