【发布时间】:2018-04-19 13:05:38
【问题描述】:
我正在尝试实现这个写入/通知处理示例 (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());
}
});
我尝试使用 rxjava1 和 rxjava2 编写代码,但在这两种情况下我都收到了 apScanDataNotificationObservable.first() 的编译时错误。它说“Observable 中的 first(byte[]) 不能应用于 ()”。所以我不知道我应该将什么参数传递给第一种方法。
【问题讨论】:
标签: java android rx-java2 rxandroidble