android-beacon-library: Huawei Blocks Scans When Screen is Off

Expected behavior

An application should be able to detect beacon region exit or entrance regardless of the application state: either foreground or background.

Actual behavior

When an application is in the background mode and screen is locked after some iterations of BeaconManager’s scanning you can see the following error in logs: E/BtGatt.GattService: App 'package_name' is scanning too frequently on screen off

After that each subsequent iteration causes the same error. After first appearance of this error exit from beacon’s region may happen (if was entered previously) and no more any region entrance can be detected.

Steps to reproduce this behavior

  1. Configure the BeaconManager for background scanning like that:
beaconManager.setBackgroundMode(true);
beaconManager.setBackgroundScanPeriod(5000L);
beaconManager.setBackgroundBetweenScanPeriod(30000L);
  1. Start the application
  2. Go to the background using “Home” button
  3. Lock the device’s screen
  4. See device’s logs by tag “scan” without package filters

Mobile device model and OS version

Samsung Galaxy S7 (Android 7.0) Huawei Honor 8 (Android 7.0)

Android Beacon Library version

2.11

As I know it is a quite common issue related to Android’s N DOZE mode. Some other beacon manufacturers (kontaktio, estimote) faced the same issue (with exact same case and error) lately. Mostly, the following official restriction mentioned: “Since Nougat, every application is allowed to start/stop BLE scan a maximum of 5 times per 30s.” but with the AltBeacon library the issue occurs even if I configure the BeaconManager like that:

beaconManager.setBackgroundScanPeriod(200L);
beaconManager.setBackgroundBetweenScanPeriod(120000L);

I’ve read issues #506, #509 and #512 but didn’t found working solution. I really like AltBeacon library, it works so great but this issue totally confused me. Please, help. Maybe I missed something.

Thank you!

IMPORTANT: This forum is reserved for feature requests or reproducible bugs with the library itself. If you need help with using the library with your project, please open a new question on StackOverflow.com.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 60 (29 by maintainers)

Most upvoted comments

In my experience, I still get bluetooth scan results up to 1 minute after screen goes off, however, once that time is up, I always get empty list of results for scan. The only workaround I found so far is to send a notification every N minutes to turn the screen on and keep getting results for another minute only for Huawei devices. This would reduce battery life but it’s the only think that’s worked so far.