java - MTU 更改如下示例
问题描述
我正在编写一个使用 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 没有问题。感谢您的帮助!
解决方案
右括号的数量似乎有误。试试下面的代码:
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)));
};
推荐阅读
- tensorflow - 我可以使用不同版本的 Tensorflow 来减小 heroku slug 的大小吗
- html - 具有相同类的几个元素。但我只能得到第一个,为什么?
- python - 在python中将数据框除以一个数字
- github - 如何使用 waka-box
- c# - 如何在 NLog C# 的不同目标中提及不同的时区
- azure-data-factory - ADF 数据流中的 Azure 表存储接收器
- javascript - 在 Next.js + Redux-saga 中刷新窗口时如何设置授权标头?
- flutter - 热重载、热重启和完全重启有什么区别?
- python - Django:使用对象属性过滤查询
- python - 使用 Kubernetes python 客户端列出命名空间中的所有资源