androidkotlinaltbeacon

AltBeacon - No beacon found when screen is off


BLE library : AltBeacon (v. 2.20.3) Android version : 15 Test Device : Pixel 6a

I'm developing a BLE gateway app. It's supposed to run all the time in the background, scanning for beacons and sending their advertising messages to the server.

Right now everything runs fine, except if the screen is OFF. Behaviors :

What am I missing ?


Solution

  • The problem is caused by using an old version of the Android Beacon Library combined with a perfect storm of testing and configuration conditions. The solution is to upgrade to the latest Android Beacon Library (version 2.21.0 as of this writing). Logs indicated that the OP was using version 2.20.3.

    A change in Android 14 altered screen-off behavior so Bluetooth scans don't work on Pixel devices unless a non-empty Bluetooth scan filter was configured. This caused all screen-off detections to fail. The Android Beacon Library was updated to address this Android change on November 11, 2024.

    The problem only affects apps running on non-Samsung devices, that do a constant Bluetooth scan with a 100% duty cycle in the background. Logs showed that all three of these things were true for the OP:

    2025-02-19 09:10:03.603 20993-20993 BeaconManager           com.elainnovation.saagcoldchain      D  API setBackgroundBetweenScanPeriod 
    ...
    2025-02-19 09:10:03.693 20993-20993 BeaconService           com.elainnovation.saagcoldchain      I  beaconService version 2.20.3 is starting up on the main process
    ...
    2025-02-19 09:10:04.002 20993-20993 CycledLeSc...orLollipop com.elainnovation.saagcoldchain      D  Using an empty scan filter since this is 8.1+ on Non-Samsung
    1
    

    The reason that configuring IntentScanStrategy worked for the OP, is because that scan strategy always uses scan filters. This is essentially a workaround that forces old versions of the Android Beacon Library to use non-empty scan filters on Pixel Devices with Android 14+ and the screen off.

    While upgrading the library is the proper solution to the general problem, the use of the IntentScanStrategy is a good idea for apps that are seeking to do 100% duty cycle scanning when the app is in the background.