2014-05-01 21 views
0

当我的代码不起作用时,我开始使用该项目,发现here,并将其与我的moto-x上的自定义蓝牙设备一起运行。针对与配置文件的一般属性,我找回数据从下面的代码:readCharacteristic没有返回自定义属性的数据

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但设置通知没有解决我的问题。

有什么建议吗?

回答

0

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

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

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

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

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

上参考servicesListClickListnerthis page

+0

感谢您的意见。我检查并设置了PROPERTY_READ位。 – Thom

+0

你有解决它吗?我也想知道有什么问题 – user2450263

+0

没有。开始认为这与设备有关。 – Thom