android - RxAndroidBle 更快地接收通知

标签 android bluetooth-lowenergy rxandroidble

我对 RxJava 还很陌生。我现在尝试 RxAndroidBle 并将其与 BLE 的 Android API 实现进行比较。我的外设一次发送大量通知(512b block 中大约 30kB)。在 Rx 中,接收全部消息大约需要 10-12 秒。 当我尝试使用 Android API 时,大约需要 2-3 秒。

在我的 RxAndroidBle 实现中,我按照示例应用程序中的建议进行操作:

connectionObservable
    .flatMap(rxBleConnection -> rxBleConnection.setupNotification(UUID.fromString(mCharacteristicUUID)))
    .doOnNext(notificationObservable -> runOnUiThread(this::notificationHasBeenSetUp))
    .flatMap(notificationObservable -> notificationObservable)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(
        this::onNotificationReceived,
        this::onNotificationSetupFailure
    );

有什么办法可以让它更快吗?

最佳答案

在您的代码 fragment 中,通知在主线程上使用,该线程也用于刷新 UI。如果您不更新 UI 并且希望获得尽可能高的性能,您可以删除 .observeOn(AndroidSchedulers.mainThread()) 行。

示例只是示例 - 它们很少针对特定用例(本例中的性能)进行优化。

记住your other question并且当使用普通 Android API 和 RxAndroidBle 时,操作系统或您的外设似乎工作方式有所不同,因此可能还值得问一个问题,这两种实现是否在相同的条件下工作。

关于android - RxAndroidBle 更快地接收通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50857496/

相关文章:

android - 如何将 json 对象转换为 android 中的字符串..?

android - 如何在 android 中创建 7incs avd 模拟器?

Android DialogFragment 在屏幕旋转时崩溃

android - 附近的消息 api : how to retrieve pictures and videos?

android - setupNotification 返回 "Error already connected"而没有发送连接请求

android - Flutter 中的 OAuth2 身份验证

android - 蓝牙网关 : onClientConnParamsChanged()

如果在手机锁定(屏幕关闭)时启动,iOS 后台任务不会保持事件状态

android - RxAndroidBle - 如何断开所有连接的设备?

android - 在 RxJava 中使用多个 .subscribe() 语句