RxAndroidBLE setupNotification 错过第一个通知

RxAndroidBLE setupNotification misses first notification

我连接的 ble 固件会在通知订阅后立即发送当前值。

例如,订阅电池电量通知特性将 return 订阅时的 50%,并在发生变化时继续通知。

这适用于示例 ble 应用程序,并且在订阅后接收、处理和显示值,但不适用于 rxandroidble。

我正在使用以下设置通知。它适用于后续通知,但似乎没有收到初始通知,就好像它仍在设置通知一样:

Disposable notifyDisposable = connectionObservable
                    .flatMap(rxBleConnection -> rxBleConnection.setupNotification(characteristic))
                    .doOnNext(notificationObservable -> L.d(TAG, "notification setup for: " + characteristic.toString()))
                    .flatMap(notificationObservable -> notificationObservable)
                    .subscribe(
                            data -> onNotificationReceived(data, notifyEvent),
                            this::onNotificationSetupFailure
                    );

有没有办法让setupNotification在写入订阅标志之前准备好,以便它可以立即处理接收到的数据?

是的,有一个 API 用于更改通知设置的行为:RxBleConnection.setupNotification(BluetoothGattCharacteristic/UUID, NotificationSetupMode)

在您的情况下,只需使用:

rxBleConnection.setupNotification(characteristic, NotificationSetupMode.QUICK_SETUP);