且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android BLE信标在不同手机型号上的扫描

更新时间:2023-01-24 08:14:46

不幸的是,您需要停止并重新开始扫描以获取其他回调.这正是在 Android信标库(停止扫描每一个1.1秒,然后立即重新启动.如果操作系统没有为每个广告进行回调,则可以使每个周期获得一个回调.

Unfortunately, you need to stop and restart scanning to get additional callbacks. This is exactly how it is implemented in the Android Beacon Library, which stops scanning every 1.1 seconds and then immediately restarts. This makes it possible to get at one callback per cycle in cases where the operating system is not making a callback for every advertisement.

目前尚不清楚这在设备和操作系统版本之间是如何变化的.在具有Android 4.3的Nexus 4上,可连接BLE广告与不可连接BLE广告的扫描行为有所不同.可连接的广告每个扫描周期仅引起一个广告回调,而不可连接的广告每个扫描周期接收多个回调.在其他设备和操作系统版本上,此行为可能会有所不同,这就是为什么必须进行循环才能获得广泛的兼容性.

It is unclear exactly how this varies between devices and operating system versions. On the Nexus 4 with Android 4.3, scanning behavior was different for connectable BLE advertisements vs. non-connectable BLE advertisements. Connectable advertisements cause only one advertisement callback per scan cycle, whereas non-connectable advertisements receive multiple callbacks per scan cycle. This behavior may vary on other devices and OS versions, which is why cycling is necessary for wide compatibility.

在具有Android 5.0的Nexus 5设备上,新的扫描API始终为来自同一设备的每个BLE广告返回多个回调,无论该广告是否可连接.但是,搭载Android 5.0的Nexus 4设备仍然只能获得一个可回调广告的广告回调,直到扫描停止并重新启动.这似乎是在驱动程序级别实现的,因此每个ROM映像可能有所不同.

On Nexus 5 devices with Android 5.0, the new scanning APIs always return multiple callbacks for each BLE advertisement from the same device, regardless of whether the advertisement is connectable or not. Nexus 4 devices with Android 5.0, however still only get one advertisement callback for connectable advertisements until the scan is stopped and restarted. This appears to be implemented at the driver level, so it is may be different for each ROM image.