Search code examples
androidbatterymanager

How frequently are ACTION_BATTERY_CHANGEDs sent, in real devices?


In the emulator, if I set power capacity to a value different from the current value, my BroadcastReceiver's onReceive is called with the new value. (I've registered with ACTION_BATTERY_CHANGED.)

In a real device, whose battery is discharging from 100 to 20 percent over a period of a few days, will my onReceive method be called:

  • exactly 80 times,
  • more than 80 times or
  • fewer than 80 times?

Re: possible duplicate question - I'm also concerned about the handler not being called often enough. I've also not made the mistake of registering a broadcast receiver from within another broadcast receiver.


Solution

  • It seems like the most common behavior is to send exactly 80 messages, but some devices will send more or fewer. This varies dramatically among real devices, and so it will have to be benchmarked for the specific devices you'll be using, or handled in the general case.

    For most devices I've worked with, ACTION_BATTERY_CHANGED will be sent exactly 80 times in that scenario. (The intent will also be sent when the device is plugged and unplugged.)

    However, for a small number of models, the message is sent every time the battery temperature changes. This can happen very frequently, depending particularly on how much processing the tablet is doing. I'm working from memory, but I believe the Verizon Ellipsis 7 tablet behaves like this.

    Also, some devices apparently send messages fewer than once per 1% change in battery level. Here is an example of more frequent messages, and here is an example of fewer messages.