我正在编写一个使用RxAndroidBle的Android应用程序,为了支持我的设备,我需要一个更高的MTU
我遵循了提供的库示例:https://github.com/Polidea/RxAndroidBle/wiki/Tutorial:-MTU-negotiation
但是它没有编译
private ObservableTransformer<RxBleConnection, RxBleConnection> mtuNegotiationObservableTransformer = upstream -> {
return upstream.doOnSubscribe(ignoredDisposable -> Log.i("MTU", "MTU negotiation is supported")
.flatMapSingle(connection ->
connection.requestMtu(GATT_MTU_MAXIMUM)
.doOnSubscribe(ignoredDisposable -> Log.i("MTU", "Negotiating MTU started"))
.doOnSuccess(mtu -> Log.i("MTU", "Negotiated MTU: " + mtu))
.ignoreElement()
.andThen(Single.just(connection)));
};
编译器消息是:无法解析方法'flatmapsingle'
为什么它不起作用?在代码的其他部分,我使用.flatMapSingle没问题。 感谢您的帮助!
答案 0 :(得分:0)
右括号的数量似乎有误。尝试以下代码:
private ObservableTransformer<RxBleConnection, RxBleConnection> mtuNegotiationObservableTransformer = upstream -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return upstream.doOnSubscribe(ignoredDisposable -> Log.i("MTU", "MTU negotiation is not supported")); // added a closing bracket here
}
return upstream
.doOnSubscribe(ignoredDisposable -> Log.i("MTU", "MTU negotiation is supported")) // and here
.flatMapSingle(connection ->
connection.requestMtu(GATT_MTU_MAXIMUM)
.doOnSubscribe(ignoredDisposable -> Log.i("MTU", "Negotiating MTU started"))
.doOnSuccess(mtu -> Log.i("MTU", "Negotiated MTU: " + mtu))
.ignoreElement()
.andThen(Single.just(connection)));
};