Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RxAndroidBLE:在没有服务发现的情况下启用特征通知_Android_Bluetooth Lowenergy_Rxandroidble - Fatal编程技术网

RxAndroidBLE:在没有服务发现的情况下启用特征通知

RxAndroidBLE:在没有服务发现的情况下启用特征通知,android,bluetooth-lowenergy,rxandroidble,Android,Bluetooth Lowenergy,Rxandroidble,我最近才开始使用RxAndroidBLE 2,我正在寻找一种解决方案,可以在不必调用discoverServices()的情况下启用特性通知。 就我而言,打电话需要很多时间(5-10秒)。确保该特性存在。 我在互联网上找到了几种解决方案。但是,在每种情况下都隐式调用discoverServices()。到目前为止,我的实现看起来像 private void onConnectionReceived(RxBleConnection rxBleConnection) { rxBle

我最近才开始使用RxAndroidBLE 2,我正在寻找一种解决方案,可以在不必调用discoverServices()的情况下启用特性通知。 就我而言,打电话需要很多时间(5-10秒)。确保该特性存在。 我在互联网上找到了几种解决方案。但是,在每种情况下都隐式调用discoverServices()。到目前为止,我的实现看起来像

private void onConnectionReceived(RxBleConnection rxBleConnection) {

        rxBleConnection.discoverServices()
                .flatMap(rxBleDeviceServices -> {
                    return rxBleDeviceServices.getCharacteristic(MY_UUID_RX);
                })
                .flatMapObservable(bluetoothGattCharacteristic -> {
                    BluetoothGattDescriptor cccDescriptor = bluetoothGattCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID);
                    Completable enableNotificationCompletable = rxBleConnection.writeDescriptor(cccDescriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                    Completable disableNotificationCompletable = rxBleConnection.writeDescriptor(cccDescriptor, BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE).onErrorComplete();
                    return rxBleConnection.setupNotification(bluetoothGattCharacteristic, NotificationSetupMode.COMPAT)
                            .doOnNext(notificationObservable -> notificationHasBeenSetUp())
                            .flatMap(notificationObservable -> notificationObservable)
                            .mergeWith(enableNotificationCompletable)
                            .doOnDispose(disableNotificationCompletable::subscribe); // fire and forget
                })
                .observeOn(AndroidSchedulers.from(handlerThread.getLooper()))
                .subscribe(this::onNotificationReceived, this::onNotificationSetupFailure);
    }

谢谢你的支持

当设备连接到新的外围设备时,它需要执行服务发现过程以获取属性(例如特征)句柄

即使确保存在具有给定UUID的特征,设备仍需要获取其句柄以执行低级别的BLE操作。根据您的外设配置,Android操作系统可能会缓存发现的属性句柄,以便在后续连接中重用

当执行服务发现过程时,Android操作系统总是使用完整的发现-它迭代所有服务/特征/描述符-如果要发现更多的属性,则需要更长的时间。通过减少外围设备上的属性数量,可以减少执行该过程所需的时间

(另一方面,iOS只允许发现特定/最小的属性子集,以加快进程)


我希望这能回答您的问题。

当设备连接到新的外围设备时,它需要执行服务发现过程以获取属性(例如特征)句柄

即使确保存在具有给定UUID的特征,设备仍需要获取其句柄以执行低级别的BLE操作。根据您的外设配置,Android操作系统可能会缓存发现的属性句柄,以便在后续连接中重用

当执行服务发现过程时,Android操作系统总是使用完整的发现-它迭代所有服务/特征/描述符-如果要发现更多的属性,则需要更长的时间。通过减少外围设备上的属性数量,可以减少执行该过程所需的时间

(另一方面,iOS只允许发现特定/最小的属性子集,以加快进程)


我希望这能回答您的问题。

非常感谢您的详细回答。。。我帮了大忙,非常感谢你详细的回答。。。他帮了我很多