【发布时间】:2017-06-19 04:47:53
【问题描述】:
作为标题,
为简单起见,如果我想使用 different UUID 执行两次读取操作:
(我知道 RxAndroidBle 提供了多次读取功能)
Observable<RxBleConnection> ob = device.establishConnection(false);
ob.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(CHAR_WIFI_SSID))
.subscribe(
characteristicValue -> {
//2. then read Successfully here !!!!!
},
throwable -> {
}
);
ob.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(CHAR_WIFI_SECURITY_MODE))
.subscribe(
characteristicValue -> {
},
throwable -> {
//1. I got BleAlreadyConnectedException error first !!!!
}
);
为什么第二个 subscribe() 得到 BleAlreadyConnectedException ?
==========更新==========
我找到了解决方案, 如果我修改
device.establishConnection(false) ==> device.establishConnection(false).compose(new ConnectionSharingAdapter())
ConnectionSharingAdapter 会做这样的事情:
sourceObservable.replay(1).refCount();
保留 source observable 发出的最后一个
【问题讨论】:
-
我不知道 rxandroidble。但我认为你想要的是
Observable.share。 -
我想我找到了问题所在。这是 BleAlreadyConnectedException...
标签: rx-java rx-android rxandroidble