BroadcastReceiver 在几个小时后停止在小米上工作

BroadcastReceiver stop working on Xiaomi after couple of hours

我正在使用 Awareness API for my project and receiving actions via BroadcastReceiver. This is the question with my code: . 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 and 并为我的应用关闭节电功能),但似乎没有任何效果。

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.

正如这一段所说:

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

然后你说:

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

几个小时后 设备可能会节省更多能源

您正在收听 "Fence API" 以注册用户当前环境的变化它可能会耗电,因此您收不到广播您可能需要更改设备设置以允许使用位置等传感器GPS 和其他相关传感器

我认为您的问题与电池优化有关。此功能从引入打盹模式的 Android Marshmallow 开始可用。这是一种减少后台应用程序电池消耗的方法,但在您的情况下,您应该为您的应用程序禁用它。