Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.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
Android RX可撤销多特征通知和读/写_Android_Rx Java_Rx Android_Rxandroidble - Fatal编程技术网

Android RX可撤销多特征通知和读/写

Android RX可撤销多特征通知和读/写,android,rx-java,rx-android,rxandroidble,Android,Rx Java,Rx Android,Rxandroidble,我在设置多个特征的通知时遇到问题。 我已经阅读了文档,其中许多示例只涉及非常细微的情况 我的用例如下所示: 1.扫描设备 2.用户选择要连接的设备(连接持续到应用关闭) 3.订阅许多特性的通知 4.一次读/写单个特征,在某些情况下,一次读/写多个特征我现在可以工作了。问题是我需要使用rxbeconnection的一个实例来实现以后的连接这是我的多写解决方案 mConnObservable.flatMapSingle(rxBleConnection -> { return

我在设置多个特征的通知时遇到问题。 我已经阅读了文档,其中许多示例只涉及非常细微的情况

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

我现在可以工作了。问题是我需要使用
rxbeconnection
的一个实例来实现以后的连接

这是我的多写解决方案

 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);

你试过写一些代码吗?创建一个数据流以满足您的需要?您能否共享用于使其正常工作的代码?我遇到了同样的事情。