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



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

此外,我有一个在后台运行的服务,它可以执行定期扫描,在我测试过的所有设备中,除了一个新的Moto X之外,应用程序都能正常工作。该应用程序被阻止,不执行扫描。有什么想法吗??

提前非常感谢!!

安卓信标库允许多个应用程序同时扫描信标,而不会相互干扰这是因为Android BLE扫描API可以跟踪哪些应用程序正在进行扫描。如果应用程序A和B都开始扫描,而应用程序B停止扫描,操作系统将继续扫描并将结果发送给应用程序A。

为了证明这一点,我在运行Android 4.4.3的Moto G上安装了Beacon ReferenceApplication的两个不同副本。应用程序包名称进行了轻微修改,以允许同时安装,默认扫描速率在应用程序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具有进程id 15841,而应用程序B具有进程id 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

相关内容

最新更新