【发布时间】:2019-06-10 07:05:25
【问题描述】:
我正在用 kotlin 协程做一些实验,特别是我想从polidea 库返回我的协程一个 RxBleDevice。 但是,Polidea scanBleDevices 函数在订阅时返回 Disposable。根据我的代码,有什么方法可以将 RxBleDevice 返回到我的协程?
这是我的代码,目前无法编译:
val scanDevices: Deferred<RxBleDevice> = GlobalScope.async {
rxBleClient.scanBleDevices(ScanSettings.Builder()
.build(), filterBuilder.setDeviceName(bikeBleName).build())
.subscribe(
{ scanResult ->
// Process scan result here.
scanResult.bleDevice
},
{ throwable ->
// Handle an error here.
}
)
}
【问题讨论】:
标签: android kotlin bluetooth-lowenergy kotlinx.coroutines