5

Is it possible to calculate remaining battery time in hours and minutes? Also, would it be able to calculate this time depending on if I'm using a certain app? Is it even possible to get such information? If you could please give me advice on how to do that, I'd be very thankful.

Alex
  • 488
  • 2
  • 5
  • 20
Ambitious Person
  • 295
  • 1
  • 3
  • 15
  • Never know the code, but for some battery app developers, such as DU Battery, they can calculate the remaining battery live. – Anggrayudi H May 13 '15 at 07:35
  • 2
    @pskink it's not real life, it's android, everything is possible here. So i am wondering about battery and i am sure, it is possible. But how ?, that is the most biggest question in my mind these time. I'll find it out but it takes some time that's what i am care about. – Ambitious Person May 13 '15 at 07:35
  • @AnggrayudiH yes, that's why i am searching about it. – Ambitious Person May 13 '15 at 07:36
  • is there any Library for that?? – Ambitious Person May 13 '15 at 07:38
  • again, you cannot do that, it depends on many future factors like cpu usage, screen brightness, network usage etc, the same you cannot say you will live 90 years no matter if you take care of yourself or you drink, smoke and take drugs – pskink May 13 '15 at 07:42
  • @pskink may be you are right. But "Du Battery" app do that in their app. So can you tell me how it is possible to them? – Ambitious Person May 13 '15 at 07:47
  • they just get the current level, wait 10 minutes or half an hour or whatever and get the current level again, the rest is first elementary school class math – pskink May 13 '15 at 07:50

3 Answers3

2

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.

Kiril Aleksandrov
  • 2,601
  • 20
  • 27
  • Kiril Aleksandrov you are right, now i need to find out such Algorithm or Calculations for my app. Thanx for all your helps But if you find out something please let me know. – Ambitious Person May 13 '15 at 07:55
2

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.

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
-2

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

  • Please read my question once again, i know that but what i want to know is Remaining Time of Battery. Not current % of battery. – Ambitious Person May 13 '15 at 07:31
  • @AmbitiousPerson You can only make an approximation about remaining time because some apps may consume more power. So battery level to time remaining conversion won't give correct result. –  May 13 '15 at 07:45
  • App you mentioned above is also shows, how much battery takes if you open certain app and shows it's time of remaining for that app. – Ambitious Person May 13 '15 at 07:48