简体   繁体   中英

BroadcastReceiver stop working on Xiaomi after couple of hours

I'm using Awareness API for my project and receiving actions via BroadcastReceiver . This is the question with my code: link . The problem is that everything works fine in all android version except in Xiaomi devices. Where BroadcastReceiver not receiving anything after couple of hours. I have tried many solution for this (such as this and this and turning battery saving off for my app), but nothing seems to work.

Google Awareness :

And whilst doing so, the API collates data from multiple sources to ensure that the data provided is both accurate and of a high quality. It also takes into account both the power and memory consumption when accessing these signals - helping to ensure that the battery life and memory usage of our applications do not have a detrimental effect on the users device.

As this paragraph says:

It also takes into account both the power and memory consumption when accessing these signals

and you say:

The problem is that everything works fine in all android version except in Xiaomi devices. Where BroadcastReciver not receiving anything after couple of hours

after couple of hours device may going to save more energy

You are listening for "Fence API" to register for changes in the users current environment it may consumes power and thus you do not receive broadcasts you may need to change the device settings to allow using of sensors such as location GPS and other relevant sensors

I think your problem is about battery optimization. This feature is available beginning from Android Marshmallow, that introduced Doze mode. It's a way of reducing battery consumption for background apps, but in your case you should disable it for your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM