首页 文章

Android Beacon Library设置刷新率

提问于
浏览
0

我正在尝试提高我的Beacon App的更新率 . 目前 Beacons itself 设置为"I am here!" -rate为500ms .

我读到 Android Beacon Library 的默认刷新率设置为1100ms,这似乎是这种情况 .

但似乎我无法改变这个刷新率(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 Beacon Library扫描的刷新率吗?谢谢! :)

UPDATE: 我调试了我的应用程序,这里是logCat日志:

https://www.dropbox.com/s/p2bajo7bp5c1j8j/BeaconLog.txt?dl=0

它是包含所有日志的文本文件 .

**更新2:**由@davidgyoung提供的答案,更新率正确更改为200毫秒 . 每次在 setRangeNotifier 中检测到信标时我都在进行控制台日志,这在 onBeaconServiceConnect 方法中被调用,你可以通过时间戳清楚地告诉你这个控制台日志太慢(大约一秒钟) . 它应该至少每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

1 回答

  • 0

    根据发布的日志,看起来扫描周期成功更改为200毫秒 . 我怀疑这是有效的,更高层次的其他事情是让更新不会超过一秒钟 .

    06-17 19:03:14.461  10161-10161/de.mediatoni.beaconProto3 D/CycledLeScanner﹕ Scan started
    ...
    06-17 19:03:14.661  10161-10161/de.mediatoni.beaconProto3 D/CycledLeScanner﹕ Done with scan cycle
    

相关问题