【发布时间】:2016-06-16 20:11:06
【问题描述】:
我正在尝试提高我的 Beacon 应用程序的更新率。目前,信标本身被设置为“我在这里!”-速率为 500 毫秒。
我读到 Android Beacon Library 的默认刷新率设置为 1100 毫秒,似乎是这样。
但似乎我无法更改此刷新率(Android 信标库的)。我试过了:
@Override
public void onBeaconServiceConnect() {
// create the necessary region for the Beacon App and give it the Sensorberg UUIDs or parse "null" if it doesn't matter
final Region region = new Region("myBeacons", null, null, null);
beaconManager.setForegroundScanPeriod(200l); // 200ms
beaconManager.setForegroundBetweenScanPeriod(0l); // 0ms
try {
beaconManager.updateScanPeriods();
} catch (RemoteException e) {
Log.e(TAG, "Cannot talk to service" + (e));
}
OnCreate方法首先创建Manager的一个实例beaconManager = BeaconManager.getInstanceForApplication(this);
然后通过BeaconManager.setRssiFilterImplClass(ArmaRssiFilter.class);设置距离检测模式。
之后,我使用 beaconManager.getBeaconParsers().add(new BeaconParser() 设置信标数据布局 .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));.
现在我通过 beaconManager.bind(this); 启动管理器 然后 OnCreate 方法关闭。
稍后我的 onBeaconServiceConnect 方法我尝试加快刷新率(上面发布的代码),但在运行应用程序时似乎没有任何改变。它仍然超过1秒。我的 logCat 中也没有“无法调用服务”。
有人可以帮我更频繁地设置 Android 信标库中扫描的刷新率吗?谢谢! :)
更新:我确实调试了我的应用,这里是 logCat 日志:
https://www.dropbox.com/s/p2bajo7bp5c1j8j/BeaconLog.txt?dl=0
这是一个包含所有日志的文本文件。
** 更新 2:** 根据@davidgyoung 提供的答案,更新速率正确更改为 200 毫秒。每次在 onBeaconServiceConnect 方法中调用的 setRangeNotifier 中检测到信标时,我都会执行控制台日志,您可以通过时间戳清楚地看出此控制台日志太慢(大约一秒钟)。它应该至少每 500 毫秒(因为这是信标的设置)。那么,减缓这一进程的原因可能是什么?我有一个 Galaxy S5 neo,应该还不错,而且应用程序很小。
控制台校验码:
// check for available data from the Beacons
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
// for each Beacon print the data and do the following functions
for(final Beacon oneBeacon : beacons) {
Log.d(TAG, "distance: " + oneBeacon.getDistance() + "id: " + oneBeacon.getId1() + "/" + oneBeacon.getId2() + "/" + oneBeacon.getId3());
这段代码的日志输出:
06-18 14:19:27.101 19937-20235/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0001 id2: 3788 id3: 2001年 06-18 14:19:27.891 19937-20275/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0000 id2: 3788 id3: 2000 06-18 14:19:28.111 19937-20300/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0002 id2: 3788 id3: 2002 06-18 14:19:28.701 19937-20302/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0000 id2: 3788 id3: 2000 06-18 14:19:28.811 19937-20337/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0001 id2: 3788 id3: 2001 06-18 14:19:28.821 19937-20338/de.mediatoni.beaconProto3 D/BeaconService﹕检测到信标:id1: 73676723-7400-0000-ffff-0000ffff0002 id2: 3788 id3: 2002
【问题讨论】:
-
你玩过扫描设置吗?
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder(); scanSettingsBuilder.setReportDelay(0); scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY); -
我不确定为什么这不起作用。在我看来它应该如此。如果您使用
beaconManager.setDebug(true)打开调试日志记录,然后在更改扫描间隔之前和之后捕获 30 秒左右的 LogCat 输出,这可能会有所帮助。如果你能做到这一点并将日志发布到某个地方,我会看看。 -
@davidgyoung 我已经用日志更新了帖子。它说:06-17 19:03:13.641 10161-10161/de.mediatoni.beaconProto3 D/BeaconManager﹕将扫描周期更新为 200, 0
标签: android altbeacon android-ibeacon beacon