Calculating remaining time of battery live

不想你离开。 提交于 2019-11-29 11:02:30

Estimating the remaining battery life is based on analytics. As the other people said you have to listen for battery level changes and in addition you have to keep track of them. After some time you will have enough data to calculate what is the average time the battery lasts. In addition you know when the battery drains fast and when drains slow so you can improve your estimation based on this. Also you will know in what time the user charges the devices. There are a lot of events that can be tracked and using the battery level. In addition you can also track when the screen is on or off. The algorithm of calculating the remaining battery life depends on you :)

I hope this explains (at least a bit) the idea of the estimation the battery life.

I don't know the code, but I can help you the logic/formula for this question:

  1. Collect all information from the battery statistics, and count the usage in total. Then calculate the usage per second, how much the battery was drained per second.
  2. Get the battery capacity in mAh, and calculate the remaining live with this formula: total capacity per speed of the usage.

Oddly enough, for some battery app developers know the code, such as DU Battery Saver.

You can use BatteryManager library to checkout the battery status with EXTRA_LEVEL:

int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);

Unfortunately, you can get the remaining time only with approximation because some apps may consume more power.

Cheers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!