无法使用 scanBleDevices 进行扫描
Cannot use scanBleDevices to scan
我第一次在 kotlin 上尝试这个库,因此我读到为了先扫描我需要用它来实现它
implementation "com.polidea.rxandroidble2:rxandroidble:1.10.0"
,创建一个RxBleClient并设置扫描参数,但是好像是方法scanBleDevices()的问题。
我尝试了存储库描述中出现的代码和 kotlin 示例中的代码。
使用描述中的代码,只有 scanBleDevices 上有错误
rxBleClient = RxBleClient.create(this)
val scanSubscription = rxBleClient.scanBleDevices(
new ScanSettings.Builder()
// .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // change if needed
// .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // change if needed
.build()
// add filters if needed
)
.subscribe(
{
// Process scan result here.
},
{
// Handle an error here.
}
);
// When done, just dispose.
scanSubscription.dispose();
使用 kotlin 示例中的代码,Observable 也有错误显示 No type arguments expected for class Observable
private fun scanBleDevices(): Observable<ScanResult> {
val scanSettings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.build()
val scanFilter = ScanFilter.Builder()
//.setDeviceAddress("B4:99:4C:34:DC:8B")
// add custom filters if needed
.build()
return rxBleClient.scanBleDevices(scanSettings, scanFilter)
}
方法 scanBleDevices() 出现问题,该方法提示请求 scanSettings 和 scanFilter 的警报,它们已被正确使用:
None of the following functions can be called with the arguments supplied.
scanBleDevices(ScanSettings!, vararg ScanFilter!) defined in com.polidea.rxandroidble2.RxBleClient
scanBleDevices(vararg UUID!) defined in com.polidea.rxandroidble2.RxBleClient
如果编译器抱怨 ScanSettings
和 ScanFilter
然后检查那些 类 的包,如果你从 com.polidea.rxandroidble2
或 android.bluetooth.le
导入它们(或相似)
库在此 API 中仅接受来自 com.polidea.rxandroidble2
包的 ScanSettings
和 ScanFilter
类。
我第一次在 kotlin 上尝试这个库,因此我读到为了先扫描我需要用它来实现它
implementation "com.polidea.rxandroidble2:rxandroidble:1.10.0"
,创建一个RxBleClient并设置扫描参数,但是好像是方法scanBleDevices()的问题。
我尝试了存储库描述中出现的代码和 kotlin 示例中的代码。
使用描述中的代码,只有 scanBleDevices 上有错误
rxBleClient = RxBleClient.create(this)
val scanSubscription = rxBleClient.scanBleDevices(
new ScanSettings.Builder()
// .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // change if needed
// .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // change if needed
.build()
// add filters if needed
)
.subscribe(
{
// Process scan result here.
},
{
// Handle an error here.
}
);
// When done, just dispose.
scanSubscription.dispose();
使用 kotlin 示例中的代码,Observable 也有错误显示 No type arguments expected for class Observable
private fun scanBleDevices(): Observable<ScanResult> {
val scanSettings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.build()
val scanFilter = ScanFilter.Builder()
//.setDeviceAddress("B4:99:4C:34:DC:8B")
// add custom filters if needed
.build()
return rxBleClient.scanBleDevices(scanSettings, scanFilter)
}
方法 scanBleDevices() 出现问题,该方法提示请求 scanSettings 和 scanFilter 的警报,它们已被正确使用:
None of the following functions can be called with the arguments supplied.
scanBleDevices(ScanSettings!, vararg ScanFilter!) defined in com.polidea.rxandroidble2.RxBleClient
scanBleDevices(vararg UUID!) defined in com.polidea.rxandroidble2.RxBleClient
如果编译器抱怨 ScanSettings
和 ScanFilter
然后检查那些 类 的包,如果你从 com.polidea.rxandroidble2
或 android.bluetooth.le
导入它们(或相似)
库在此 API 中仅接受来自 com.polidea.rxandroidble2
包的 ScanSettings
和 ScanFilter
类。