I am trying to implement this example of write/notification handling (Using RxAndroidBle, how do I subscribe to responses from writing to a characteristic?).
connectionObservable
.flatMap((Function<RxBleConnection, Observable<Observable<byte[]>>>)
(RxBleConnection rxBleConnection) -> {
return rxBleConnection.setupNotification(TX_CHAR_UUID);
},
(BiFunction<RxBleConnection, Observable<byte[]>, Observable<byte[]>>)
(rxBleConnection, apScanDataNotificationObservable) -> {
return Observable.combineLatest(
rxBleConnection.writeCharacteristic(RX_CHAR_UUID, getInputBytes()),
apScanDataNotificationObservable.first(),
new BiFunction<byte[], byte[], byte[]>() {
@Override
public byte[] apply(byte[] writtenBytes, byte[] responseBytes) throws Exception {
return responseBytes;
}
}
);
}
).flatMap(new Function<Observable<byte[]>, Observable<byte[]>>() {
@Override
public Observable<byte[]> apply(Observable<byte[]> observable) throws Exception {
return observable;
}
})
.first()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<byte[]>() {
@Override
public void accept(byte[] bytes) throws Exception {
Log.i("Ivan1", "notification response...." + bytes.toString());
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Log.i("Ivan", "notification response...." + throwable.toString());
}
});
I tried to write with rxjava1 and rxjava2, but in both cases I got a compile time error for apScanDataNotificationObservable.first(). It says "first(byte[]) in Observable cannot be applied to ()". So I dont know what argument I should pass to the first method.