Android Oreo Background Service Limitations

Hi! I have developed my app for Android Nougath (Api 25) about some time but now i have to update the targetSdk to Android Oreo (Api 26).
In my application i have a service that run in background and start a beacon scan with this parameters "beaconManager.setBackgroundScanPeriod(5,8); "
and set a MonitoringListener.
So I want that continuously scan for beacons (for 8 hours).
With the update to Oreo this don’t happen: when i start the app, the beacon are recognized but when i close the app, after a while, the service in background don’t work anymore.
What can I do ? Who is the problem???
Is android Oreo that kill the service or kill BeaconManager ?

Thanks

Yes, with Android O and later, background services are not really a good fit for long-term BLE scanning. Arguably, also true on earlier versions of Android, as some Android smartphone manufacturers customize their OSes to also kill background services.

In our new Proximity SDK (https://github.com/estimote/android-proximity-sdk), we switched to a foreground service instead. It requires showing a notification to inform the user about the activity of your app, but as a reward, it’s much more reliable.

See also: this StackOverflow post about the same topic:
https://stackoverflow.com/a/51176580/1900855

Thanks for the response.
I need to use this sdk https://github.com/Estimote/Android-SDK/ (now i’m using 1.4.1)
(not proximity sdk).
If I promote my background service into a foreground service, can it work well?
Between service in execution of my application android I see a service named BeaconService not created by me. I thinks that service take care of bluetooth scanning for beacon. That service will work well too ?or will the system kill it?

That SDK always runs scanning in a background service, and I can’t think of any way to promote it to a foreground service. We’re also not actively maintaining/updating that SDK anymore, so I wouldn’t expect compatibility updates for Android 8, 9, and beyond.

If you have an existing deployment and can’t change to Proximity SDK because you have older beacons or can’t reconfigure them from iBeacon to Estimote Monitoring, you can try the open-source Android Beacon Library, which works with iBeacon and has support for Android 8 and later:

https://altbeacon.github.io/android-beacon-library/

Although if you’re gonna be changing SDKs, you could just as well switch to Estimote Proximity SDK, and get full compatibility with Estimote’s stack (: It supports any Estimote Proximity and Location Beacons newer than hardware revision “D”. (at this time, that’s hardware revs “F”, “G”, “I”, and “J”)

Hello @heypiotr: Thanks for responding.
Could you please direct me to any articles about continued monitoring of beacons even after the app is killed (user swipes away or Android OS kills the app)?

Starting with Android O, you can simply use the new PendingIntent scan:

https://developer.android.com/reference/android/bluetooth/le/BluetoothLeScanner#startScan(java.util.List<android.bluetooth.le.ScanFilter>,%20android.bluetooth.le.ScanSettings,%20android.app.PendingIntent)