首页 文章

Android BLE onCharacteristicChanged未调用

提问于
浏览
0

我正在开发一个包含Bluegiga BLE113模块和Android应用程序的项目 . 在Bluegiga模块上,我设置了几个特征 . 对于一个特征,我定义了一个描述符来激活客户端通知(在我的例子中,客户端是Android应用程序) . BLE113模块的特征定义如下所示:

:
<characteristic uuid="dcfa2671-974d-4e4a-96cd-6221afeabb62" id="ez1_flow_data_out">
  <!-- org.bluetooth.descriptor.gatt.characteristic_user_description -->
  <description>Data to transmit to Android device</description>
  <properties write="true" read="true" />
  <value variable_length="true" length="255" type="hex" />
  <!-- org.bluetooth.descriptor.gatt.client_characteristic_configuration -->
  <descriptor uuid="2902">
    <properties write="true" read="true" const="false" />
    <!-- Bit 0 = 1: Notifications enabled -->
    <value type="hex">0001</value>
    </descriptor>
:
:
</characteristic>

在Android方面,我根据Android蓝牙低功耗指南在 onServicesDiscovered(...) 回调中设置了通知:

characteristic = gatt.getService(BLEuuids.DATAFLOW_SERVICE).getCharacteristic(BLEuuids.DATAFLOW_OUT_CHARACT);
//Enable local notifications
gatt.setCharacteristicNotification(characteristic, true);
//Enabled remote notifications
BluetoothGattDescriptor desc = characteristic.getDescriptor(BLEuuids.DATAFLOW_OUT_DESCRIPT);
boolean test;
test = desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);  // return value = true
test = gatt.readDescriptor(desc);  // return value = true
test = gatt.writeDescriptor(desc);  // return value = true

但是,如果我使用Bluegiga模块的串行接口更改DATAFLOW_OUT_CHARACT特征UUID的值,则不会在我的Android应用程序上触发预期的回调 onCharacteristicChanged(...) .

1 回答

  • 2

    尽量不要阅读描述符 . 设置后立即写描述符 . 正确的读取将覆盖您的设置并返回相同的值?

相关问题