简体   繁体   English

未调用 BLE Gatt onCharacteristicChanged 方法

[英]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.

相关问题 BLE GATT onCharacteristicChanged在订阅通知后没有调用 - BLE GATT onCharacteristicChanged not called after subscribing to notification 在Android BLE GATT服务中未调用onCharacteristicChanged - onCharacteristicChanged is not called in Android BLE GATT servcies 订阅通知后未调用BLE GATT onCharacteristicChanged - BLE GATT onCharacteristicChanged not called after subscribe to notification 为什么在 Wear OS 设备中调用 Android BLE gatt 回调方法 onCharacteristicChanged 回调的速率低于智能手机? - Why Android BLE gatt callback method onCharacteristicChanged callback is called in lower rate in Wear OS device than on smartphone? 未调用Android BLE onCharacteristicChanged() - Android BLE onCharacteristicChanged() not called onCharacteristicChanged没有用BLE调用 - onCharacteristicChanged not called with BLE Android BLE onCharacteristicChanged未调用 - Android BLE onCharacteristicChanged not called BLE oncharacteristicistic已更改未在android 4.4和5中调用 - BLE oncharacteristicchanged not called in android 4.4 and 5 Android Ble Glucose - onCharacteristicChanged 未调用 - Android Ble Glucose - onCharacteristicChanged not called 从未调用Android BLE onCharacteristicRead和onCharacteristicChanged - Android BLE onCharacteristicRead and onCharacteristicChanged never called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM