蓝牙连接在信标和智能手表之间的区别

huangapple go评论87阅读模式
英文:

Bluetooth connectivity difference between beacons and smartwatches

问题

我正在调查是否可以使用Android的JobScheduler与后台的BluetoothLeScanner结合使用,以便在检测到特定蓝牙设备时立即得到通知。

问题:
文档中提到,我的应用可能需要超过15分钟才能收到有关设备的通知,而且似乎不是实时的。

另一方面,测试Garmin智能手表表明它们能够立即通知应用程序,没有延迟。

蓝牙信标和智能手表的实现方式是否存在一些根本性的不同?或者Android是否更倾向于接收智能手表的蓝牙广告?

英文:

I was investigating possibility to use android JobScheduler in combination with Background bluetoothLeScanner to get notified about specific bluetooth device in vicinity as soon as it is detected.

Problem:
Documentation says, that it could take more than 15 minutes for my app to be notified about device and it doesn't seem to be realtime.

On the other hand, testing garmin smartwatches showed, that they manage to notify app with no delay.

Is there some fundamental differences between how beacons and smartwatches are implemented? Or is android preferring bluetooth advertisements from smartwatches?

答案1

得分: 1

你可以在Android上在几秒内检测到蓝牙信标,但JobScheduler不适合快速完成此任务。 JobScheduler的问题在于它只允许您每15分钟左右运行一次代码,加减10分钟。因此,如果您使用它来安排定期扫描,可能会出现延迟。

在Android 8+上的替代方法是使用基于Intent的扫描,它会在检测到信标后立即将扫描结果传递给广播接收器。通常情况下,这将在五秒内提供新的检测结果。

我写了一篇博客文章,详细描述了这是如何工作的,并展示了设置扫描的示例代码。

开源的Android Beacon库使用这种技术来提供快速检测结果。

英文:

You can detect Bluetooth Beacons within seconds on Android, but the JobScheduler is not helpful to do it quickly. The problem with the JobScheduler is that it will only let you run code every 15 minutes +/- 10 mins. So if you use it to schedule periodic scans, there may be delays.

The alternative on Android 8+ is to use an Intent-backed scan, which will deliver scan results to a Broadcast receiver as soon as your beacon is detected. This typically delivers new detections within five seconds.

I wrote a blog post that describes in detail how this works, and shows sample code for setting up a scan.

The open source Android Beacon Library uses this technique to deliver fast detections.

huangapple
  • 本文由 发表于 2023年3月8日 15:47:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定