javaandroidbluetooth-lowenergybeacon

Android Beacon Library - Is there any way we can change the interval in which the range notifier updates, which by default is "once every second"


By default, the notifier updates every second. However, if the library is being used to track one's location using BLE Beacons, this doesn't seem very effective since the user marker will be moving in a dull and unnatural way.

Is there any way we can change this update interval, so that the user's movement feels much smoother?


Solution

  • The Android Beacon Library returns ranging results every 1.1 seconds by default. You can customize the scan period by calling a method like this:

    beaconManager.setForegroundScanPeriod(100)

    The above will change the callback rate to 100 milliseconds (10 times per second).

    Be careful, however, with setting this period to be very small. The smaller you make it, the more likely it is that no beacons will be detected in that short interval. In that case, you will get a ranging callback with an empty list of beacons.

    While some beacons advertise once very ~100ms (10Hz), not all advertisements are received by phones due to a number of factors. (About 80-90 percent it typical at short range.) Also, be aware that many battery powered beacons reduce the advertisement rate to once every 1000 ms or even 5000ms to save power. If you have a beacon like this, you will get empty ranging callbacks over 90% of the time when setting a short scan period.

    An alternative approach when moving a map marker is to animate it from the old position to the new position over the update interval. So if you leave the scan period at the default 1100 milliseconds, and animate the pointer to move over 1100ms, then it will feel more natural. (More sophisticated techniques are also possible where you calculate a heading and velocity and animate the pointer according to that, correcting as you get new updates.)