我正在开发一个 Android 应用程序,它在 Android 设备和 BLE 外围设备(一个简单的发射器)之间打开一个 BLE 连接。
外围设备被编程为具有我发现的多个读取特性。 当我尝试启用通知时出现问题。
第一个总是返回 true,然后它开始触发我的通知回调,其他总是返回 false 值。
List<BluetoothGattDescriptor> descrittoriDellaChar = getListaDescrittoriDaCharact(charact);
Boolean status = null;
for (int i = 0; i < descrittoriDellaChar.size(); i++) {
BluetoothGattDescriptor TargetDescriptor = descrittoriDellaChar.get(i);
byte[] valore = TargetDescriptor.getValue();
if (valore != BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) {
getCharDiLettura().add(charact);
TargetDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
//TargetDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
boolean success=false;
while(success==false) {
success = gattGlobale.writeDescriptor(TargetDescriptor);
}
status = gattGlobale.setCharacteristicNotification(charact, true);
}
}
boolean prio= gattGlobale.requestConnectionPriority(gattGlobale.CONNECTION_PRIORITY_HIGH);
我使用相同的方法,因为我只有 1 个特征要读取,现在它不再起作用了。
最佳答案
一个接一个地同步发送读写请求是行不通的,因为 android 一次只允许一个挂起的 GATT 操作(这就是它返回 false 的原因)。您必须以某种方式将工作排入队列,并在上一个请求的回调 (onCharacteristicRead/onCharacteristicWrite/onDescriptorWrite) 到达后继续发送下一个请求。
关于android - BLE Android,无法启用超过 1 个读取特性通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39661417/