【问题标题】:Android BLE onCharacteristicChanged not called未调用 Android BLE onCharacteristicChanged
【发布时间】:2014-06-23 12:47:56
【问题描述】:

我正在开发一个项目,其中包括一个 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(...)

【问题讨论】:

    标签: android bluetooth-lowenergy android-4.4-kitkat android-4.3-jelly-bean bluegiga


    【解决方案1】:

    尽量不要读描述符。 设置后立即写入描述符。 正确地读取会覆盖你的集合,然后你写回相同的值吗?

    【讨论】:

    • 你是对的,在评论test = gatt.readDescriptor(desc); 之后,通知被正确触发。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多