首页 > 解决方案 > BLE 通知冻结所有其他活动读取特性

问题描述

从启用通知后

 BluetoothGatt gatt= leBluetoothService.getmBluetoothGatt();
        gatt.setCharacteristicNotification(chracteristicId, enable);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }



        BluetoothGattDescriptor descriptor = chracteristicId.getDescriptor(
                UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        gatt.writeDescriptor(descriptor);

我无法从任何其他特征读取数据。它冻结了所有特征。为什么会这样?启用通知后,它也不会从该特征读取数据。

编辑:

在调用设置通知后,所有读取和通知开始堆积而不是执行。我对每个操作都使用了同步静态方法。

  public static void AddOperation(Operation opr) {
        operations.add(opr) ;
        Log.d("operations",String.valueOf(operations.size()));
        if (currentOperation ==null){
            currentOperation = opr;

            request(opr);


        }
    }

    private static synchronized void request(Operation operation) {
        Log.d("kala", ""+operation);
        operation.execute();


    }
    public static synchronized void operationCompleted() {
        currentOperation = null;
        if (operations.peek() != null) {
            currentOperation = operations.poll();
            Log.d("kalaa", ""+currentOperation);
            currentOperation.execute();
        }

    }

所有读取操作都执行良好,但如果特性已通知属性,则操作开始堆积。有什么方法可以查看何时设置通知?

标签: androidbluetooth-lowenergy

解决方案


推荐阅读