蓝牙不是在阅读每一个特征

时间:2016-11-10 11:12:13

标签: android bluetooth

我的应用中的蓝牙问题。我有很多特点,只能阅读2.当我尝试阅读更多时,我没有得到任何回调。我读到我应该创建队列,但不知道该怎么做。有什么帮助吗?

这是我的特点:

 private void registerParametersCharacteristics(List<BluetoothGattCharacteristic> characteristics) {
        for (BluetoothGattCharacteristic characteristic : characteristics) {
            UUID characteristicUuid = characteristic.getUuid();
            if (Characteristics.EON_PARAMS_EDDYSTONE_UID_CHAR.equals(characteristicUuid)) {
                euidCharacteristic = characteristic;
                Log.e(TAG, "registerParametersCharacteristics: EUID" );
            }
            else if (Characteristics.EON_PARAMS_EDDYSTONE_EID_CHAR.equals(characteristicUuid)) {
                eeidCharacteristic = characteristic;}
            else if (Characteristics.EON_PARAMS_EDDYSTONE_URL_CHAR.equals(characteristicUuid)) {
                eurlCharacteristic = characteristic;}
            else if (Characteristics.EON_PARAMS_EDDYSTONE_TLM_CHAR.equals(characteristicUuid)) {
                etlmCharacteristic = characteristic;}
            else if (Characteristics.EON_PARAMS_EDDYSTONE_UID_UUID.equals(characteristicUuid)) {
                eUidUUidCharacteristic = characteristic;}
            else if (Characteristics.EON_PARAMS_EDDYSTONE_URL_UUID.equals(characteristicUuid)) {
                eUrlUuidCharacteristic = characteristic;
                Log.e(TAG, "registerParametersCharacteristics: EurlUUID" );
            }
            else if (Characteristics.MINOR_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
                minorCharacteristic = characteristic;}
            else if (Characteristics.MAJOR_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
                majorCharacteristic = characteristic;
            }
            else if (Characteristics.UUID_CHARACTERISTIC_UUID.equals(characteristicUuid)){
                uuidCharacteristic = characteristic;
            }
            else if (Characteristics.INTERVAL_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
                intervalCharacteristic = characteristic;
            }
            else if (Characteristics.TX_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
                txCharacteristic = characteristic;
            }
            else if (Characteristics.BATTERY_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
                batteryCharacteristic = characteristic;
                Log.e(TAG, "registerParametersCharacteristics: BAT" );
            }
            Log.e(TAG, "registerParametersCharacteristics: " + characteristic.getUuid().toString() );
        }
    }

这是我的onServicediscovered方法:

@Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            super.onServicesDiscovered(gatt, status);
            if (status == BluetoothGatt.GATT_SUCCESS) {
                List<BluetoothGattService> services = gatt.getServices();
                for (BluetoothGattService service : services) {
                    registerService(service);
                    Log.e(TAG, "onServicesDiscovered: " + service.getUuid().toString() );
                }
                callback.connectedStateChanged(true);
            } else
                disconnect();
        }
        @Override
        public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
            super.onCharacteristicRead(gatt, characteristic, status);
            characteristicValueRead(characteristic);
            BluetoothCommunicationManager.getInstance().processNext();
        }

我写了这个队列已经失去了两天而无法完成。提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

你应该使用&#39;命令&#39;设计模式。基本上,您将拥有抽象类或接口,单个&#39;执行(..)&#39;方法。您将创建类,扩展该命令&#39; class,但每个实现都会做自己的工作。 然后,您可以创建&#39; ArrayList&#39;,将所有任务添加到其中,然后在&#39;中处理这些任务。循环如:

for (Command c : commands){
 c.execute(..);
{