Reputation: 534
Is there a way to get a Subscription
from an already connected device using RxAndroidBle? I can't seem to find a way aside from disconnecting and connecting again.
Upvotes: 0
Views: 543
Reputation: 3222
You are probably not interested in getting the Subscription
from an already connected device but rather to get an instance of the emitted RxBleConnection
.
It is more of an RxJava
question then:
You can get this kind of behaviour (an Observable<RxBleConnection>
that will emit RxBleConnection
to any next subscriber if it had already emitted) for instance by using RxReplayingShare
. It would look like:
Observable<RxBleConnection> connectionObservable = rxBleDevice.establishConnection(false)
.compose(ReplayingShare.instance());
Then, every subscriber to the connectionObservable
will get the same RxBleConnection
as long as it will be valid.
Be careful though because sometimes BLE communication is implemented as stateful (i.e. a request-response model) and this kind of sharing may introduce some hard to spot issues.
Upvotes: 1
Reputation: 1051
No, you need to maintain the rxbleconnection
subscription and instance yourself. The library is stateless.
Upvotes: 0