【问题标题】:RxAndroidBle Multiple Characteristic Notifications and Read/WriteRxAndroidBle 多特征通知和读/写
【发布时间】:2017-04-27 20:41:27
【问题描述】:

我在设置多个特征的通知时遇到问题。 我查看了文档,其中许多示例只涵盖了非常精细的情况。

我的用例如下: 1.扫描设备 2. 用户选择要连接的设备(连接一直持续到应用程序关闭) 3.订阅许多特性的通知 4. 一次读/写单个特征,在某些情况下一次读/写多个特征

【问题讨论】:

  • 你有没有试过写一些代码?创建满足您需求的数据流?

标签: android rx-java rx-android rxandroidble


【解决方案1】:

我现在开始工作了。问题是我需要使用 RxBleConnection 的实例以供以后连接

【讨论】:

  • 你能分享你用来让它工作的代码吗?我遇到了同样的事情。
【解决方案2】:

这是我的多次写入解决方案

 mConnObservable.flatMapSingle(rxBleConnection -> {
        return rxBleConnection.writeCharacteristic(SSID, mSsidView.getText().toString().getBytes())
                .flatMap(ssidBytes -> rxBleConnection.writeCharacteristic(SSID2, mPassPhrase.getText().toString().getBytes())
                .flatMap(ssid2Bytes -> rxBleConnection.writeCharacteristic(SSID3, mSecurityModeSpinner.getSelectedItem().toString().getBytes())));
    })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(ssid3Bytes -> {
               //do something
            }, this::onError, this::onComplete);

你应该把其他的 flatMap 操作放在第一个 flatMap 中,因为你只能在第一个 flatMap 中获取 rxBleConnection

RxAndroidBle RxJava 1版本的原始解决方案:

 mConnObservable.flatMap(rxBleConnection -> {
        return rxBleConnection.writeCharacteristic(SSID, mSsidView.getText().toString().getBytes())
                .flatMap(ssidBytes -> rxBleConnection.writeCharacteristic(SSID2, mPassPhrase.getText().toString().getBytes())
                .flatMap(ssid2Bytes -> rxBleConnection.writeCharacteristic(SSID3, mSecurityModeSpinner.getSelectedItem().toString().getBytes())));
    })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(ssid3Bytes -> {
               //do something
            }, this::onError, this::onComplete);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多