android - 使用 BLE 扫描扫描过滤器
问题描述
我研究了一个使用 BLE 扫描到前台服务的应用程序。我使用库 RxBle Android 来执行扫描。</p>
private fun scanBleDevices(): Observable<ScanResult>? {
val rxBleClient = RxBleClient.create(this)
val scanSettings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.build()
val scanFilter = ScanFilter.Builder()
//.setServiceData(ParcelUuid.fromString("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), ByteArray(1))
//.setDeviceAddress("XX:XX:XX:XX:XX:XX")
.build()
return rxBleClient.scanBleDevices(scanSettings, scanFilter)
}
private fun startScan(){
Timber.e("Start SCAN")
scanBleDevices()?.let {
it.observeOn(AndroidSchedulers.mainThread())
.subscribe({ scanResult ->
//Handle scan result
}, {
Timber.e("Scan failed")
})
}
}
当我的手机屏幕被锁定时,我使用 ScanFilter 来获得扫描结果。
当我使用带有 mac 地址的 ScanFilter 时效果很好,但这不是一个真正的解决方案,因为我不想为我的所有信标指定所有 mac 地址。</p>
所以我尝试使用带有服务数据 ID 的 ScanFilter,除非我的手机屏幕被锁定,否则它可以工作。问题只是当我将我的应用程序与三星设备一起使用时,因为我有一个 Pixel 3 并且我没有这个问题。
你有解释或解决方案吗?</p>
谢谢 !
解决方案
推荐阅读
- angular - AWS Codebuild for Angular Project is successful with build error
- webforms - Could not find installable ISAM while opening excel file with OLE driver
- customization - How can I optimize yolo4-deepsort to my custom data?
- sql - Want to parse string BLOB as JSON, modify few fields and parse it back to string BIGQUERY
- visual-studio-code - VS Code 自动缩进
- java - 如何使用 JXBrowser 捕获特定元素而不是整个页面的屏幕截图?
- vue.js - 在 vue-router 中重定向时如何从 VueJS 中的 URL 传递道具?
- gradle - 在 `settings.gradle` 中为同一级别文件夹中的模块使用 Gradle `from project` 找不到
- javascript - 如何从数据表的输入端发出带有 keyup 事件的 ajax 请求?
- javascript - 我可以从 javascript 中的隐藏画布中捕获流吗?