【发布时间】:2019-09-08 12:00:17
【问题描述】:
我目前正在使用 Kotlin 开发一个 Android 应用程序。这是我对这种编程语言的第一次体验,我目前正在努力将 Java 代码示例翻译成 Kotlin。
我想在 Kotlin 中实现this 问题的答案。
我当前的实现无法编译,因为 Ovservable::from 方法似乎已被删除。
这是我目前的做法:
connectionObservable!!.flatMap { connection ->
connection.discoverServices()
.flatMap { services ->
services.getService(UUID.fromString("My UUID")).map(BluetoothGattService::getCharacteristics)
//here occurs the error, he wants a Single Source but got a observable with the ble characteristic
.flatMap { characteristics: MutableList<BluetoothGattCharacteristic> -> Observable.fromIterable(characteristics) }
.flatMap { characteristic: BluetoothGattCharacteristic ->
connection.setupNotification(characteristic)
.flatMap { observable: Observable<ByteArray> -> observable ,Pair<BluetoothGattCharacteristic, ByteArray>(characteristic, observable)}
}
}
}.subscribe { pair: Pair<BluetoothGattCharacteristic, ByteArray> ->
genericModel[pair.first.uuid] = pair.second
throwable -> { /* handle errors */ }
}
您能指出我的错误,以便我了解我做错了什么吗?
提前致谢! 乔纳斯
【问题讨论】:
-
平面图 {Observable.from(getCharacteristics) 不够?
-
我更新了代码 tro clearify。他想要一个 SingleSource 但在这行之后得到了一个 Observable
标签: android kotlin reactivex rxandroidble