最近蓝牙手环在Android9.0的手机上回连总是连接不上,老在扫描的地方onScanFailed里回调errorCode=2,errorCode共有下面4种情况:
errorCode=1;Fails to start scan as BLE scan with the same settings is already started by the app.
errorCode=2;Fails to start scan as app cannot be registered.
errorCode=3;Fails to start scan due an internal error
errorCode=4;Fails to start power optimized scan as this feature is not supported
发现BluetoothGatt.close()不管用,关闭重启手机蓝牙或者重启App是可以重新连接蓝牙,但是咱不能一碰到这个问题就让用户去重启App或者重启手机蓝牙。经过查阅各种资料,说问题的原因是:
手机在startScan扫描的过程中还没来得及stopScan ,就被系统强制杀掉了, 导致mClientIf未被正常释放,实例和相关蓝牙对象已被残留到系统蓝牙服务中, 打开app后又重新初始化ScanCallback多次被注册,导致每次的扫描mClientIf的值都在递增, 于是mClientIf的值在增加到一定程度时(最大mClientIf数量视国产系统而定 不做深究),onScanFailed 返回了 errorCode =2 。
解决办法是:重新刷新手机的蓝牙状态
public static boolean releaseAllScanClient() {
try {
Object m
354




被折叠的 条评论
为什么被折叠?



