Search code examples
javaandroidbluetoothbeacon

How to set BLE scan interval and windows no just choose mode in android?


I am a fresh man in android. I want to set BLE scan interval and windows in my android device in order to do a experiment about neighbour discovery. I search the answer on google and know that there are some definition in android's source code about BLE scan interval and windows as below

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

If I want to change the values, does it mean that I should compile the android system? Is there a better way?


Solution

  • You are free to control the equivalent if scan window and interval yourself in higher-level code by starting and stopping scanning. This is exactly what the open source Android Beacon Library does with its equivalent configurable parameters:

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