Calculating the remaining battery time

Can I calculate the remaining battery life in hours and minutes? Besides, will he be able to calculate this time depending on whether I use some kind of application? Is it possible to get such information? If you could advise me how to do this, I would be very grateful.

+5
source share
3 answers

Estimation of remaining battery life is based on analytics. As other people have said, you should listen to changes in battery level, and in addition, you should monitor them. After a while, you will have enough data to calculate how long the battery takes. In addition, you know when the battery discharges quickly and drains slowly, so you can improve your rating based on this. You will also find out what time the user charges the device. There are many events that you can track and use the battery level. In addition, you can also track when the screen is on or off. The algorithm for calculating the remaining battery life is up to you :)

I hope this explains (at least a little) the idea of ​​estimating battery life.

+2
source

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

  • Collect all the information from the statistics of the battery and calculate its use. Then count the amount of use per second, how much water was discharged per second.
  • 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 developers of applications for mobile devices, a code is known, for example, DU Battery Saver.

+2
source

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

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

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

Greetings

-2
source

All Articles