androidbeaconandroid-ibeacon

Is it necessary to use the foreground service with the android beacon library?


I am trying to build an app that simply detects beacons at all times...when running in foreground or background, after reboot, etc.

I noticed the following in the android beacon library example program...

// Uncomment the code below to use a foreground service to scan for beacons. This unlocks
// the ability to continually scan for long periods of time in the background on Andorid 8+
// in exchange for showing an icon at the top of the screen and a always-on notification to
// communicate to users that your app is using resources in the background.

My questions are...

  1. Is this really necessary?
  2. if we don't do this what are the repercussions?
  3. is there a way to do both and would that be better?
  4. how can I get the app to start scanning after reboot?

Thanks for any help.


Solution

  • On Android 8+ apps may not get beacon updates more than once every ~15 minutes when the app is in the background unless the app has a foreground service. If you do not have one, the app will be terminated within 10 minutes of entering the background and will then start waking up every ~15 minutes to look for beacons. Callbacks will only happen on these 15 minutes.

    There is no other way allowed by the operating system.

    The Android Beacon Library will automatically launch an app into the background to look for beacons on reboot as described here.