BLE Android,无法启用超过 1 个读取特性通知
BLE Android, can't enable more than 1 notify on read characteristics
我正在开发一个 Android 应用程序,它在 Android 设备和 BLE 外围设备(一个简单的发射器)之间打开一个 BLE 连接。
外围设备被编程为具有我发现的多个读取特征。
当我尝试启用通知时出现问题。
第一个总是 return 为真,然后它开始触发我的通知回调,其他总是 return 假值。
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 操作(这就是它 returns 错误的原因)。您必须以某种方式将工作排入队列,并在上一个请求的回调 (onCharacteristicRead/onCharacteristicWrite/onDescriptorWrite) 到达后继续发送下一个请求。
我正在开发一个 Android 应用程序,它在 Android 设备和 BLE 外围设备(一个简单的发射器)之间打开一个 BLE 连接。
外围设备被编程为具有我发现的多个读取特征。 当我尝试启用通知时出现问题。
第一个总是 return 为真,然后它开始触发我的通知回调,其他总是 return 假值。
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 操作(这就是它 returns 错误的原因)。您必须以某种方式将工作排入队列,并在上一个请求的回调 (onCharacteristicRead/onCharacteristicWrite/onDescriptorWrite) 到达后继续发送下一个请求。