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 :
- Screen ON, app in foreground : scans performed, beacons detected
- Screen ON, app in background : same
- Screen ON, app killed : same
- Screen ON, device locked : same
- Screen OFF : scans performed, callback triggered, but no beacons detected
What am I missing ?
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 :
- Screen ON, app in foreground : scans performed, beacons detected
- Screen ON, app in background : same
- Screen ON, app killed : same
- Screen ON, device locked : same
- Screen OFF : scans performed, callback triggered, but no beacons detected
What am I missing ?
Share Improve this question asked 2 days ago SaphirelSaphirel 3702 silver badges11 bronze badges1 Answer
Reset to default 0Android requires that scan filters be used for Bluetooth scans when the screen is turned off. The Android Beacon Library is designed to accommodate this by enabling a scan filter only when the screen is off. Sometimes, however, misconfigurations of the beacon format can cause the scan filter to fail to match the beacon, causing screen-off detections with the scan filter to fail, even though it works with the screen on without the scan filter.
Double check any BeaconParser expressions that your app is using to make sure they are absolutely correct. One common cause of this problem is for manufacturer advertisements (e.g. iBeacon and AltBeacon), which include a manufacturer code. If a non-standard manufacturer code advertised by the beacon does not match those built-in to the library (code 0x004c = Apple, Inc. for iBeacon, code 0x0118 = Radius Networks for AltBeacon) the scan filter will not match and screen off detections will fail.
If you are unsure about the manufacturer code your beacon is advertising, you can use my BeaconScope app in the Play Store which will tell you the raw bytes of the advertisement so you can see the manufacturer code.
If this is the problem, you can fix it by adding extra manufacturer codes to your BeaconParser. For example, if you find your beacon is advertising a non-standard manufacture code of 0x1111 for iBeacon, use this to add that in addition to the standard 0x004c manufacturer code:
val iBeaconParser = BeaconParser("iBeacon")
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
iBeaconParser.setHardwareAssistManufacturerCodes(intArrayOf(0x004c, 0x1111))