3

I am trying to read the capacity of the battery in code, but so far I haven't succeeded. Does anyone know how to read the battery capacity programmatically?

I need a code snippet or some reference as to where to search.

jimmym715
  • 1,512
  • 1
  • 16
  • 25
Lukap
  • 31,523
  • 64
  • 157
  • 244

1 Answers1

0

You might want to look at this question. You use the ACTION_BATTERY_CHANGED intent to get the information. You would use the BatteryManager to get the constants. I believe that constant that you would be looking for is EXTRA_SCALE

Community
  • 1
  • 1
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
  • I looked in the documentation and it says very little about what the extra_scale returns, it says "Extra for ACTION_BATTERY_CHANGED: integer containing the maximum battery level." What is the unit of measurement ? Does this extra_scale value have some boundary ? – Lukap Oct 26 '11 at 16:15
  • for scale I get value 100, I guess this is the maximum value that level can reach, it meas the level is measured in "%". – Lukap Oct 26 '11 at 16:28
  • I'm not sure either. The documentation is very vague, as you said. You should do some testing to find out. Print the value into logcat. – The.Anti.9 Oct 26 '11 at 16:29
  • Ah yes, that is probably what that is. What unit are you actually looking for? `EXTRA_VOLTAGE` gives you voltage, but as far as I can tell there's no other measure of capacity available. – The.Anti.9 Oct 26 '11 at 22:03
  • well, the capacity of my battery is 1200mA h. But I guess this is not possible to be read. :( – Lukap Oct 27 '11 at 07:06