【问题标题】:readCharacteristic not returning data for custom attributesreadCharacteristic 不返回自定义属性的数据
【发布时间】:2014-05-01 17:14:32
【问题描述】:

当我的代码不起作用时,我从找到here 的项目开始,并在我的 moto-x 上针对我们的自定义蓝牙设备运行它。针对配置文件的一般属性,我从以下代码中获取数据:

public void readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.readCharacteristic(characteristic);
}

异步返回数据:

    public void onCharacteristicRead(BluetoothGatt gatt,
                                     BluetoothGattCharacteristic characteristic,
                                     int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
        }
    }

如果我在心率监视器上运行此代码,这也有效。

如果我在没有默认配置文件的情况下针对我们的自定义属性之一运行它,则数据永远不会返回。永远。

谷歌搜索包括:Cannot read characteristic. Android BLE,但设置通知并没有解决我的问题。

有什么建议吗?

【问题讨论】:

    标签: java android bluetooth-lowenergy android-4.4-kitkat


    【解决方案1】:

    我认为 PROPERTY_READ, PROPERTY_WRITE 未在您的自定义属性中设置为启用。

    检查BluetoothGattCharacteristic PROPERTIES - 我没有意识到需要在 BLE 硬件上启用 PROPERTY_WRITE、PROPERTY_READ,这浪费了很多时间。

    检查属性的部分应该是这样的:

    if ((characteristic.getProperties() && 
    BluetoothGattCharacteristic.PROPERTY_READ)> 0) {
         // toast or log here
          }
    

    这些启用/禁用应用程序或任何应用程序连接到蓝牙低功耗设备

    请参考servicesListClickListnerthis page

    【讨论】:

    • 感谢您的建议。我检查并设置了 PROPERTY_READ 位。
    • 你解决了吗?我也想知道那里有什么问题
    • 不。开始认为这与设备有关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2019-01-24
    • 2021-05-14
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多