【问题标题】:BLE Android, can't enable more than 1 notify on read characteristicsBLE Android,不能启用超过 1 个关于读取特性的通知
【发布时间】:2016-09-23 12:58:46
【问题描述】:

我正在开发一个 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 bluetooth-lowenergy


    【解决方案1】:

    一个接一个地同步发送读取和写入请求不起作用,因为 android 一次只允许一个挂起的 GATT 操作(这就是它返回 false 的原因)。一旦上一个请求的回调(onCharacteristicRead/onCharacteristicWrite/onDescriptorWrite)到达,您必须以某种方式将工作排入队列并继续发送下一个请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多