如何设置BLE扫描间隔和窗口只是在android中选择模式?

时间:2016-11-21 12:50:14

标签: java android bluetooth beacon

我是android的新手。我想在我的Android设备中设置BLE扫描间隔和窗口,以便进行有关邻居发现的实验。我在谷歌搜索答案,并知道android's source code中有关于BLE扫描间隔和窗口的定义如下

/**
 * Scan params corresponding to regular scan setting
 */
private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 500;
private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 5000;
private static final int SCAN_MODE_BALANCED_WINDOW_MS = 2000;
private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;

/**
 * Scan params corresponding to batch scan setting
 */
private static final int SCAN_MODE_BATCH_LOW_POWER_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_POWER_INTERVAL_MS = 150000;
private static final int SCAN_MODE_BATCH_BALANCED_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_BALANCED_INTERVAL_MS = 15000;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_INTERVAL_MS = 5000;

如果我想更改值,是否意味着我应该编译android系统?还有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

通过启动和停止扫描,您可以自由控制等效扫描窗口和自己在更高级别代码中的间隔。这正是开源Android Beacon Library对其等效可配置参数的作用:

 beaconManager.setForegroundScanPeriod(...);
 beaconManager.setForegroundBetweenScanPeriod(...);