gpt4 book ai didi

bluetooth-lowenergy - com.polidea.rxandroidble2.exceptions.BleScanException : Scan failed because application registration failed (code 6) Samsung Galaxy 8

转载 作者:行者123 更新时间:2023-12-04 13:17:51 27 4
gpt4 key购买 nike

目前我正在处理一个涉及 ble 设备的应用程序。我创建了一个服务并授予了蓝牙应用程序所需的所有权限并启用了蓝牙。当服务启动时,它会扫描 ble 设备并连接到它。但是有时在扫描时它会给我这个异常(exception)。

com.polidea.rxandroidble2.exceptions.BleScanException:扫描失败,因为应用程序注册失败(代码 6)

我正在使用这个库

[ https://github.com/Polidea/RxAndroidBle][1]

这是我的服务

package mypackage.name

import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import com.cambfit.android.bluetoothdriver.*
import com.cambfit.android.core.base.viewmodel.SingleLiveEvent
import com.orhanobut.logger.Logger
import com.polidea.rxandroidble2.RxBleClient
import com.polidea.rxandroidble2.RxBleDevice
import com.polidea.rxandroidble2.exceptions.BleScanException
import com.polidea.rxandroidble2.scan.ScanFilter
import com.polidea.rxandroidble2.scan.ScanResult
import com.polidea.rxandroidble2.scan.ScanSettings
import dagger.android.AndroidInjection
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import java.util.concurrent.TimeUnit
import javax.inject.Inject

class BluetoothService : Service() {

@Inject
lateinit var rxBleClient: RxBleClient

private val binder by lazy { BluetoothServiceBinder() }

private val compositeDisposable by lazy { CompositeDisposable() }
private lateinit var scanDisposable: Disposable

override fun onCreate() {
AndroidInjection.inject(this)
super.onCreate()
observeBlueToothState()
}

override fun onDestroy() {
compositeDisposable.dispose()
super.onDestroy()
}

override fun onBind(intent: Intent?): IBinder? {
return binder
}

private fun observeBlueToothState() {

scanDisposable = rxBleClient.observeStateChanges()
.startWith(rxBleClient.state)
.switchMap { state ->
when (state) {
RxBleClient.State.READY -> {
Logger.d("READY")
return@switchMap scanDevices()
}

RxBleClient.State.BLUETOOTH_NOT_AVAILABLE -> {
Logger.e("BLUETOOTH_NOT_AVAILABLE")
return@switchMap Observable.empty<ScanResult>()
}

RxBleClient.State.LOCATION_PERMISSION_NOT_GRANTED -> {
Logger.w("LOCATION_PERMISSION_NOT_GRANTED")
return@switchMap Observable.empty<ScanResult>()
}

RxBleClient.State.BLUETOOTH_NOT_ENABLED -> {
Logger.w("BLUETOOTH_NOT_ENABLED")
binder.enableBluetoothEvent.call()
return@switchMap Observable.empty<ScanResult>()
}

RxBleClient.State.LOCATION_SERVICES_NOT_ENABLED -> {
Logger.w("LOCATION_SERVICES_NOT_ENABLED")
return@switchMap Observable.empty<ScanResult>()
}

else -> {
Logger.w("OTHER")
return@switchMap Observable.empty<ScanResult>()
}
}
}
.filter { scanResult -> scanResult.bleDevice.name != null }
.subscribe({ scanResult ->

//Logger.d(scanResult.toString())


}, { throwable ->
throwable.printStackTrace()
})

compositeDisposable.add(scanDisposable)
}

private fun scanDevices(): Observable<ScanResult> {
return rxBleClient.scanBleDevices(ScanSettings.Builder().build(), ScanFilter.Builder().build())
.retryWhen { errors ->
errors.flatMap { error ->
if (error is BleScanException) return@flatMap Observable.timer(30, TimeUnit.SECONDS)
else return@flatMap Observable.error<Exception>(error)
}
}
}

}

我们将不胜感激任何形式的帮助。谢谢。

最佳答案

这似乎是 Android 错误和/或在手机其他地方执行的过度扫描。快速谷歌搜索显示它是 a known problem

基本上您的手机系统资源已用完。

它看起来不像是可以在您的代码中以编程方式修复的东西。

解决方法是关闭/打开您的 BT,以便清除 BT 资源。

关于bluetooth-lowenergy - com.polidea.rxandroidble2.exceptions.BleScanException : Scan failed because application registration failed (code 6) Samsung Galaxy 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58412394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com