2

I can able to get the battery durability percentage(like 80%), but i don't have knowledge on to predict the time duration of battery durability. For example. 80% battery will remains 7 hours 20 mins. Can we do like this, i din't get any reference for this. Can anyone guide me on this. Thanks

RAAAAM
  • 3,378
  • 19
  • 59
  • 108

2 Answers2

0

please refer to this answer here as it describe what you should do like the following :

in your activity register to a broadCastReceiver with

Intent.ACTION_BATTERY_CHANGED

and when the Battery changed you will get the new value like the following :

int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
      batteryTxt.setText(String.valueOf(level) + "%");

this will return 70% , 80% etc .

But you can't estimate the time remaining, because some apps may consume more power. So i think battery level to time remaining conversion won't give correct result.

and please give me some feedback

Hope that helps .

Community
  • 1
  • 1
  • Thanks for the replies, the above code will return the percentage values of battery durability, which means it shows like 80% or 60 %. but i want to get the time line for 80% or 60%. – RAAAAM Feb 19 '14 at 07:12
0

I afraid that it's not possible to get precise time remains until the battery would drain.

that's because the following reasons:

  • there is no such Android API.

  • you can't build some algorithm / equation to calculate time remains, because that's depends too much on the specific user behavior and installed apps.

for example:
the life time of the battery could be doubled or even tripled in case the user won't - open the screen at all. same as if the user have 20 applications that opens network connections in unpredictable time intervals, or pulling accurate location with GPS, active state of all phone sensors and bluetooth scans, and a lot more. that's even before considering different batteries lifetime, and different android build versions, and lot's more other considerations that attempt to track them would never end.

I afraid that only thing you can do is to provide a very very rough estimation (What other apps do) based on the specific device that your app is running on + vendor specification for battery + current battery level

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98