[英]BLE Gatt onCharacteristicChanged method not called
We are facing an issue with BLE Gatt onCharacteristicChanged method.我们正面临 BLE Gatt onCharacteristicChanged 方法的问题。 This method is not called.
不调用此方法。
We have enabled notification using below code:我们已使用以下代码启用通知:
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)
After this, We are sending code to BLE from onDescriptorWrite Method.在此之后,我们从 onDescriptorWrite 方法向 BLE 发送代码。
{WRITE_SERVICE_CHARACTERISTIC}.setValue({BYTE_ARRAY})
val status = mBluetoothGatt!!.writeCharacteristic(RxChar)
After sending code to BLE.将代码发送到 BLE 后。 it will response in onCharacteristicWrite Method.
它将在 onCharacteristicWrite 方法中响应。 but we are not getting any response in onCharacteristicChanged Method via Notify Service.
但是我们没有通过通知服务在 onCharacteristicChanged 方法中得到任何响应。
Same commands are working in other BLE Scanner Application but my application facing an issue.相同的命令在其他 BLE 扫描仪应用程序中工作,但我的应用程序面临问题。
Please help us to solve the issue.请帮助我们解决问题。
Thanks谢谢
You are overriding the notification settings of the descriptor with the indication setting:您正在使用指示设置覆盖描述符的通知设置:
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
descriptor.value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
You probably only need notifications and can remove the enabling of indications:您可能只需要通知并且可以取消启用指示:
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)
If you truly need both notifications and indications you have to set the values like this:如果您确实需要通知和指示,则必须设置如下值:
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE | BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
The |
的
|
operator does a bitwise OR operation and therefore combines both flags into one运算符执行按位或运算,因此将两个标志合并为一个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.