L. *_*emi 3 android bluetooth-lowenergy
我正在开发一个Android应用程序,它在Android设备和BLE pheripheral(一个简单的发送器)之间打开一个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);
Run Code Online (Sandbox Code Playgroud)
我使用相同的方法,因为我只有1个特征来阅读,现在它不再起作用了.
一个接一个地同步发送读取和写入请求不起作用,因为android一次只允许一个挂起的GATT操作(这就是它返回false的原因).一旦前一个请求的回调(onCharacteristicRead/onCharacteristicWrite/onDescriptorWrite)到达,您必须以某种方式排队工作并继续发送下一个请求.
| 归档时间: |
|
| 查看次数: |
1811 次 |
| 最近记录: |