Open Kitsopappas opened 6 years ago
I don't know how power saving works on Xiaomi devices, although it sounds like a proprietary enhancement as the functionality does match any known behavior on stock Android AOSP 7.x. It is always very hard to come up with solutions to proprietary Android changes as they are closed source and tend to be undocumented.
Two possible workarounds:
beaconManager.setEnableScheduledScanJobs(true)
. This will use ScheduledJobs to do the scanning instead of long-running services. Again, it is possible that Xiaomi will allow scanning on scheduled jobs. The disadvantage of this approach is that scans can only happen in the background once every ~15 minutes, not the 13 seconds you describe. It may also be useful to capture system level log messages when the scan results are blocked to see if they offer any clue as to what Xioami is doing.
I have an application written in Ionic/Cordova and I need to range for beacons when the app is in the background.
Expected behavior
I scan for beacons in the background every 13 seconds iBeaconManager.setBackgroundScanPeriod(13000); and the library should not stop returning results. In the foreground the ranging does not stop.
Actual behavior
After a short period of time (aprox 1min), whilst the app is in the background, the ranging stops returning beacon results and returns an empty array instead. The ranging will not return any results even if I move the app to the foreground or restart the ranging. It will only start showing results again if we restart the mobile's bluetooth.
Steps to reproduce this behavior
0) Check if there is a power saving setting enabled for the application 1) Start scanning for ibeacons 2) Move application to the background 3) See ibeacon results returning an empty array after a while (Even if there are beacons around).
If we disable the power saving setting and restart the bluetooth then the app will return results of ibeacons nearby indefinitely.
Mobile device model and OS version
Xiaomi Note 5A Prime (Android Version 7.1.2) Xiaomi RedMi Note 4x (Android Version 7.0.0)
Android Beacon Library version
2.12.4-android8_1
Ionic Ibeacon Library
https://github.com/petermetz/cordova-plugin-ibeacon
Sample Code
Is there any way to avoid this/work around? Or should I inform the users using this application to dissable the power saving mode on their mobile phones?