Android BLE:“扫描失败,原因是应用程序注册UUID失败的原因" [英] Android BLE: "Scan failed, reason app registration failed for UUID"

查看:572
本文介绍了Android BLE:“扫描失败,原因是应用程序注册UUID失败的原因"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RxAndroidBle库开发应用程序,该库大约每30秒定期执行BLE扫描,每分钟左右执行一些BLE操作.几个小时后(通常在5到24小时之间),扫描将停止工作.每次应该开始扫描,我都会得到:

I am developing an application using the RxAndroidBle library that performs BLE scans regularly about every 30 seconds, and some BLE operations every minute or so. After a couple of hours, usually between 5 and 24h, the scan stops working. Every time a scan is supposed to be started, I get:

09-05 09:08:37.160 8160-8160/myapp D/BluetoothAdapter: startLeScan(): null
09-05 09:08:37.165 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.165 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.165 8160-8160/myapp D/BluetoothLeScanner: Start Scan
09-05 09:08:37.165 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.165 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.170 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.170 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:37.210 8160-12850/myapp D/BluetoothLeScanner: onClientRegistered() - status=133 clientIf=0
09-05 09:08:37.210 8160-12850/myapp D/BluetoothLeScanner: Registration failed, unregister clientIf = 0
09-05 09:08:37.215 8160-8160/myapp D/BluetoothLeScanner: Scan failed, reason app registration failed for UUID = 4c321920-a2b7-449a-bc24-ea4361f7a255
09-05 09:08:44.150 8160-8160/myapp V/myapp.debug: unsubscribing scan
09-05 09:08:44.150 8160-8160/myapp V/myapp.debug: Clearing scan subscription
09-05 09:08:44.150 8160-8160/myapp D/BluetoothAdapter: stopLeScan()
09-05 09:08:44.150 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:44.155 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:44.155 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:44.155 8160-8160/myapp D/BluetoothAdapter: STATE_ON
09-05 09:08:44.155 8160-8160/myapp D/BluetoothLeScanner: could not find callback wrapper

有人对导致此问题的原因或解决该问题的方法有任何想法吗?

Does anyone have any idea of what causes this problem or what can be done to fix it?

推荐答案

在Android的较早实现中,在启用蓝牙适配器的时间与执行扫描的速度之间似乎存在竞争.您可以通过尝试使用禁用的蓝牙适配器进行扫描或正在转换的适配器(或具有打开的连接并尝试读取)的适配器来触发此错误.在我的应用中导致此问题的根本问题是蓝牙子系统无法获取新的蓝牙套接字.上面的答案(用尽了关贸总协定的资源)可能是其中的一部分.较旧的Android设备中避免该问题的总体逻辑是:1.确保大约每5次扫描禁用/启用一次蓝牙适配器.这似乎有助于清除较旧的缓存数据. 2.确保在未启用蓝牙适配器的情况下不要尝试启动扫描(如果要定期禁用/启用,则可以进行此操作). 3.确保从GATT接口断开连接与进行下一次扫描之间存在延迟. 4.不要一次读取超过3个设备的GATT特性.

On the older implementations of Android there seems to be a race condition between the time a bluetooth adapter is enabled and how quickly you can do a scan. You can trigger this error by either trying to scan with a disabled bluetooth adapter or one that is transitioning (or has open connections and is trying to read). The underlying issue that was causing it in my app was the inability of the bluetooth sub system to get a new bluetooth socket. The answer above (running out of GATT resources) could be part of it. The overall logic in an older Android device to avoid this issue is: 1. Make sure you disable/enable the bluetooth adapter about every 5 scans. This seems to help clear out older cached data. 2. Make sure you don't try to initiate a scan while the bluetooth adapter is not enabled (this is made possible if you are disabling/enabling on a regular basis). 3. Make sure you have a delay between disconnecting from GATT interfaces and doing your next scan. 4. Don't try to read the GATT characteristics of any more than about 3 devices at a time.

总体而言,在较旧的Android设备中,这是不可避免的,它可以完全避免该问题,但是您可以通过仔细安排扫描/停止扫描/连接/断开连接/周期的时间来缓解此问题.

Overall, its somewhat unavoidable in an older Android device to completely avoid the problem but you can mitigate it by carefully timing your scan/stop scan/connect/disconnect/ cycle.

这篇关于Android BLE:“扫描失败,原因是应用程序注册UUID失败的原因"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆