android - BLE Android,无法启用超过 1 个读取特性通知

标签 android bluetooth-lowenergy

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

相关文章:

android - 包含 10 个线性布局的 viewflipper 的最佳实践?

android - 如何更改android软键盘按键的背景颜色?

ios - kCBAdvDataManufacturerData 中的数据不稳定

ios - 使用通知作为回调有问题吗?

ios - 使用BLE RSSI值进行邻近连接

android - 如何在不输入密码的情况下配对蓝牙设备

android EMFILE(打开的文件太多)

android - OkHttpInterceptor 从 kotlin 拦截器导航到登录 fragment

Android 应用内结算 v3 : "Can' t perform operation: queryInventory"

ios - DiscoverServices 有时从不触发