I am using a BroadcastReceiver to monitor battery level changes.

 // register the battery action receiver
    mContext.registerReceiver(this, new IntentFilter(
            Intent.ACTION_BATTERY_CHANGED));

OnReceive method is called every one level change in Battery. Is it possible to change the granularity at which the ACTION_BATTERY_CHANGED is received?

有帮助吗?

解决方案

It is not possible to set the interval between battery percentage as far as I know. However, you could filter it yourself by saving the last level at which you updated it then check if it is lower or equal to the amount you are checking for. Alternatively, you could check if it is a multiple of something (ie. 5) before continuing. Also, as Marco said, you can use other types of Intents (ie. ACTION_BATTERY_LOW or ACTION_BATTERY_OKAY) depending on what your app does.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top