I am creating an Android application that has special requirements for Bluetooth Low Energy.
I need to write a record-only description and get responses to a separate notification attribute, and I need to do this in many, many actions. Is there an Rx way to send a request on the 1st characteristic, wait for the answer on the second, and then move on to another request?
Also, to share my copy of RxAndroidBle, I thought about making some kind of BleManager Singleton, where I would expose Observables, so I can easily subscribe to them in my Presenter. I just want to avoid the need to copy the connection logic for each activity and have (ideally) a stable connection. That way, I could only expose connectionObservable and subscribe to it, so I can easily send write requests and receive notifications, but I'm sure there is a better way to do this.
This is what I have now:
@Singleton public class BleManager { private PublishSubject<Void> disconnectTriggerSubject = PublishSubject.create(); private Observable<RxBleConnection> connectionObservable; private boolean isConnected; private final UUID CTRL_FROM_BRIDGE_UUID = UUID.fromString("someUUID"); private final UUID BLE_WRITE_CHARACTERISTIC_UUID = UUID.fromString("someOtherUUID"); private final RxBleClient bleClient; private String mMacAddress; private final Context context; private RxBleDevice bleDevice; @Inject public BleManager(Context context, RxBleClient client) { Timber.d("Constructing BleManager and injecting members"); this.context = context; this.bleClient = client; } public void setMacAddress(String mMacAddress) { this.mMacAddress = mMacAddress;
android rx-java rx-android bluetooth-lowenergy rxandroidble
Frederic portaria-janicki
source share