Search code examples
javaandroidmobilealtbeacon

Workaround for bug where Android N device constantly enters / exits region when using Altbeacon


I have an Android app implementing the Altbeacon library to monitor for beacons while holding a reference to BackgroundPowerSaver(). This is working as expected except on Android N devices, where the library informs me that I am constantly entering/exiting a beacon region even though my device nor beacon are moving.

I have confirmed that this is a bug within the Altbeacon library as the reference app (linked below) also has the same issue when run on an Android N device. https://github.com/AltBeacon/android-beacon-library-reference

Is there a known work-around for this bug?


I am running the reference app with the 2.1.3 grade build on a Nexus 9 tablet with Android N and am monitoring for RadBeacon beacons. As seen in the LogCat statements, the app believes that it is entering and exiting the beacon region every ~15 seconds. However, the device nor the beacon are moving during this time. The beacon layout I have set my BeaconManager to find is "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24".

Here is the LogCat output.


Solution

  • The issue appears to be caused by a change in Android N's Developer Preview 4:

    We’ve changed the BLE Scanning behavior starting in DP4. We’ll prevent applications from starting and stopping scans more than 5 times in 30 seconds. For long running scans, we’ll convert them into opportunistic scans

    https://developer.android.com/preview/support.html

    I've opened a new issue on the Android Beacon Library Open Source Project to address this change for Android Nougat devices. Please monitor this issue for a preview fix to be released shortly. If you'd be open to test a preview build, I'd certainly appreciate it.

    EDIT: A proposed fix is available here. Please follow the instructions on the linked page to test this build with your project and let me know if it resolves the problem.