iBeacon同时扫描(Android应用程序)

时间:2014-10-07 15:20:35

标签: android bluetooth-lowenergy ibeacon ibeacon-android

我正在开发一些使用扫描设备ibeacons的应用程序。每个应用程序都有不同的扫描频率。我的问题是多个应用程序同时扫描是否存在问题。什么是堆叠蓝牙设备的访问协议?。

此外,我有一个在后台运行的服务执行定期扫描,在我测试的所有设备中,应用程序正常工作,除了一个新的Moto X.应用程序被阻止并且不执行扫描。任何想法??

提前非常感谢!!

1 个答案:

答案 0 :(得分:4)

Android Beacon Library允许多个应用程序同时扫描信标而不会相互干扰。这是有效的,因为Android BLE扫描API会跟踪哪些应用正在进行扫描。如果应用程序A和B都开始扫描,并且应用程序B停止扫描,则操作系统会继续扫描并将结果发送到应用程序A.

为了证明这一点,我在运行Android 4.4.3的Moto G上安装了两个不同的BeaconReferenceApplication副本。稍微修改了应用程序包名称以允许同时安装,并且应用程序A上的默认扫描速率设置为开启/关闭5秒,应用程序B上开启/关闭10秒。应用程序自定义如下所示:

申请A

long scanPeriod = 10000l;
long betweenScanPeriod = 10000l;
mBeaconManager.setBackgroundBetweenScanPeriod(scanPeriod);
mBeaconManager.setBackgroundScanPeriod(betweenScanPeriod);
Log.d(TAG, "Looking for beacon with minor 12345, with a scan on/off cycle of "+scanPeriod+"/"+betweenScanPeriod+" milliseconds");

申请B

long scanPeriod = 5000l;
long betweenScanPeriod = 5000l;
mBeaconManager.setBackgroundBetweenScanPeriod(scanPeriod);
mBeaconManager.setBackgroundScanPeriod(betweenScanPeriod);
Log.d(TAG, "Looking for beacon with minor 12345, with a scan on/off cycle of "+scanPeriod+"/"+betweenScanPeriod+" milliseconds");

当我同时在后台运行这两个应用程序时,应用程序A成功检测到信标直接10秒,即使应用程序B仅在停止前连续5秒成功检测到信标。应用程序B停止扫描不会影响应用程序A.您可以在下面的日志输出中自己查看结果。 (注意应用程序A的进程号为15841,应用程序B的进程号为15910)。

虽然这些测试是在Moto G上进行的,但我怀疑他们在Moto X上会有什么不同的结果,因为Moto X只是具有高端硬件的同一设备的一个版本。因此,我怀疑您看到的问题可能是特定于应用程序的问题。另外需要注意的是,Moto X和Moto G都存在硬件问题,蓝牙和WiFi无法同时正常工作。如果您在扫描信标的同时使用WiFi,如果它阻止检测,请不要感到惊讶。

10-07 13:29:05.949 D/BeaconReferenceApplication(15841): Looking for beacon with minor 12345, with a scan on/off cycle of 10000/10000 milliseconds
10-07 13:29:09.071 D/BeaconReferenceApplication(15910): Looking for beacon with minor 12345, with a scan on/off cycle of 5000/5000 milliseconds
...
10-07 13:29:15.582 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:16.119 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:16.738 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:16.942 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.072 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.250 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.372 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.375 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.660 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:17.660 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.075 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.080 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.289 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.297 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.501 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.513 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.820 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:18.822 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.035 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.040 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.438 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.441 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.540 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.542 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.643 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:19.644 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:20.699 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:20.910 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.125 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.239 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.344 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.462 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.751 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:21.969 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:22.170 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:23.016 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:23.129 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:23.340 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:23.444 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:23.654 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:24.180 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:24.818 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:25.012 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:25.113 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:25.245 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:25.424 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:25.527 D/BeaconService(15841): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345
10-07 13:29:26.353 D/BeaconService(15910): beacon detected :id1: e2c56db5-dffb-48d2-b060-d0f5a71096e0 id2: 1 id3: 12345