如题,
为简单起见,如果我想使用不同的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 发出的最后一个