2016-06-16 62 views
0

我正在尝试提高我的Beacon应用程序的更新率。目前,信标本身被设置为“我在这里!” - 速率为500ms。Android信标库设置刷新率

我看到Android信标库的默认刷新率设置为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方法首先创建管理器的一个实例beaconManager = BeaconManager.getInstanceForApplication(本);

然后设置距离检测模式为BeaconManager.setRssiFilterImplClass(ArmaRssiFilter.class);。 。

我建立之后所述信标数据布局beaconManager.getBeaconParsers()添加(新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库中扫描的刷新率吗?谢谢! :)

更新:我没有调试我的应用程序,在这里是logcat的日志:

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

它与所有日志的文本文件。

**更新2:**正如@davidgyoung提供的答案一样,更新速率正确更改为200ms。我每次在setRangeNotifier中检测到信标时都会执行控制台日志,在onBeaconServiceConnect方法中调用此方法,并且您可以清楚地告诉时间戳记此控制台日志太慢(约一秒)。它应该至少每隔500ms(因为这是信标的设置)。那么,有什么原因可能会放慢这一过程?我有一个银河S5新星应该是相当好的,应用程序只是很小。

控制台校验码:这个代码的

// 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

+0

你玩过扫描设置吗? 'ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder(); scanSettingsBuilder.setReportDelay(0); scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);' – Michiyo

+0

我不知道为什么这不起作用。它看起来应该像我一样。如果您使用beaconManager.setDebug(true)打开调试日志记录,然后在更改扫描时间间隔之前和之后捕获LogCat输出30秒左右,可能会有所帮助。如果你可以做到这一点,并在某处发布日志,我会看看。 – davidgyoung

+0

@davidgyoung我用日志更新了帖子。它说:** 06-17 19:03:13.641 10161-10161/de.mediatoni.beaconProto3 D/BeaconManager:将扫描周期更新为200,0 ** – olop01

回答

0

根据发布的日志,看起来扫描周期已成功更改为200 ms。我怀疑这是行得通的,而其他更高级别的更新不会每秒发生一次。

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 
+0

您是对的。我正在寻找这种滞后的原因。每次检测到信标时,我都会有一个控制台日志,它清楚地告诉我们时间戳,它太慢了。 (请参阅UPDATE 2) – olop01

+0

我已经创建了另一个小测试应用程序,以查看它的日志记录频率,并且每秒只更新日志,而不是每200毫秒更新一次日志。难道我的S5 Neo对它来说太慢了? 你可以看到我使用的示例代码,在这里: https://www.dropbox.com/s/1nlbq1mvwiox9zx/BeaconApp.txt?dl=0 – olop01