Java readCharacteristic不返回自定义属性的数据
当我的代码不起作用时,我开始了我找到的项目,并在我的moto-x上用我们定制的蓝牙设备运行它。针对概要文件的常规属性,我从以下代码中获取数据:Java readCharacteristic不返回自定义属性的数据,java,android,bluetooth-lowenergy,android-4.4-kitkat,Java,Android,Bluetooth Lowenergy,Android 4.4 Kitkat,当我的代码不起作用时,我开始了我找到的项目,并在我的moto-x上用我们定制的蓝牙设备运行它。针对概要文件的常规属性,我从以下代码中获取数据: public void readCharacteristic(BluetoothGattCharacteristic characteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter n
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);
}
}
如果我在心率监视器上运行此代码,这也会起作用
如果我在没有默认配置文件的情况下对某个自定义属性运行它,数据将永远不会返回。永远
谷歌搜索包括这一点:但设置通知并没有解决我的问题
有什么建议吗?我认为自定义属性中的属性“读取”、“写入”未设置为“启用” 检查-我没有意识到需要在BLE硬件上启用属性写入、属性读取,这浪费了很多时间 检查属性的部分应类似于:
if ((characteristic.getProperties() &&
BluetoothGattCharacteristic.PROPERTY_READ)> 0) {
// toast or log here
}
这些功能可启用/禁用应用程序或任何连接到蓝牙低能耗设备的应用程序
请参阅上的服务列表单击列表,谢谢您的建议。我检查并设置了属性读取位。您是否修复了它?我还想知道Therenop的问题是什么。我开始认为这和设备有关。