Android-BLE icon indicating copy to clipboard operation
Android-BLE copied to clipboard

notify问题

Open luckWenTao opened this issue 5 years ago • 1 comments

我的一个uuid服务中有俩个notifyCharacteristics uuid 我只想开启一个。但是当我通过enableNotifyByUuid打开一个后。在你的框架内部会再这个uuid写入成功之后,在下面代码中自动帮我开启另外一个notify

@Override
        public void onDescriptorWrite(BluetoothGatt gatt,
                                      BluetoothGattDescriptor descriptor, int status) {
            if (gatt == null || gatt.getDevice() == null)return;
            UUID uuid = descriptor.getCharacteristic().getUuid();
            BleLog.d(TAG, "write descriptor uuid:" + uuid);
            synchronized (locker) {
                T bleDevice = getBleDeviceInternal(gatt.getDevice().getAddress());
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    if (null != descWrapperCallback){
                        descWrapperCallback.onDescWriteSuccess(bleDevice, descriptor);
                    }
                    if (notifyCharacteristics.size() > 0 && notifyIndex < notifyCharacteristics.size()) {
                        BleLog.d(TAG, "set characteristic notification, notify_index is "+notifyIndex);
                        setCharacteristicNotification(gatt.getDevice().getAddress(), true);
                    } else {
                        BleLog.d(TAG, "set characteristic notification is completed");
                        if (notifyWrapperCallback != null) {
                            if (Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
                                    || Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)){
                                notifyWrapperCallback.onNotifySuccess(bleDevice);
                            }else if (Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE)){
                                notifyWrapperCallback.onNotifyCanceled(bleDevice);
                            }

                        }
                    }
                }else {
                    if (null != descWrapperCallback){
                        descWrapperCallback.onDescWriteFailed(bleDevice, status);
                    }
                }
            }
        }
 setCharacteristicNotification(gatt.getDevice().getAddress(), true);

请问怎么样我才能只监听一条uuid通道

luckWenTao avatar Jan 18 '21 06:01 luckWenTao

我的一个uuid服务中有俩个notifyCharacteristics uuid 我只想开启一个。但是当我通过enableNotifyByUuid打开一个后。在你的框架内部会再这个uuid写入成功之后,在下面代码中自动帮我开启另外一个notify

@Override
        public void onDescriptorWrite(BluetoothGatt gatt,
                                      BluetoothGattDescriptor descriptor, int status) {
            if (gatt == null || gatt.getDevice() == null)return;
            UUID uuid = descriptor.getCharacteristic().getUuid();
            BleLog.d(TAG, "write descriptor uuid:" + uuid);
            synchronized (locker) {
                T bleDevice = getBleDeviceInternal(gatt.getDevice().getAddress());
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    if (null != descWrapperCallback){
                        descWrapperCallback.onDescWriteSuccess(bleDevice, descriptor);
                    }
                    if (notifyCharacteristics.size() > 0 && notifyIndex < notifyCharacteristics.size()) {
                        BleLog.d(TAG, "set characteristic notification, notify_index is "+notifyIndex);
                        setCharacteristicNotification(gatt.getDevice().getAddress(), true);
                    } else {
                        BleLog.d(TAG, "set characteristic notification is completed");
                        if (notifyWrapperCallback != null) {
                            if (Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
                                    || Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)){
                                notifyWrapperCallback.onNotifySuccess(bleDevice);
                            }else if (Arrays.equals(descriptor.getValue(), BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE)){
                                notifyWrapperCallback.onNotifyCanceled(bleDevice);
                            }

                        }
                    }
                }else {
                    if (null != descWrapperCallback){
                        descWrapperCallback.onDescWriteFailed(bleDevice, status);
                    }
                }
            }
        }
 setCharacteristicNotification(gatt.getDevice().getAddress(), true);

请问怎么样我才能只监听一条uuid通道

这个应该是框架的问题,下个版本会优化这个问题,感谢支持

aicareles avatar Feb 23 '21 03:02 aicareles