6

Is there any way to read the power input from a USB connection in Android?

For example plug in a micro usb lead into the phone from either a computer USB output, a mains charger, or something similar and read the voltage and amp output?

I have no idea where to start looking for this information, and when searching I can only find battery widgets, or power consumption apps - this is not what I'm looking for, I want to be able to read how much power is being sent via the USB interface that is connected.

Many thanks.

Charles
  • 50,943
  • 13
  • 104
  • 142
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224

1 Answers1

1

Probably, You should start with BatteryManager , refer to this question for some examples of usage. I believe the data provided by BatteryManager should be enough to provide approximate calculation of what You want to (how much power is being sent via the USB). Having device id and table of devices default batteries capacities or/and users input about capacity and % difference with time interval and voltage probably would give enough info for approximate calculation of consumption

Another (dirty) way might be the following - dig android sources if ones have any info about total capacity / consumption You can obtain e.g. with java reflection. I think BatteryManager and BatteryStatsImpl could be appropriate places to start analysis from.

Community
  • 1
  • 1
sandrstar
  • 12,503
  • 8
  • 58
  • 65
  • Ah thanks, although as far as I can see this is about the output from the battery only. Also, there is no way to check for amps. I will have a look in the reference for similar classes however! :) Thanks for your help. – Thomas Clayson Sep 25 '12 at 14:19
  • hmm, You right. Depends on Your purpose You can just ask user about battery total capacity (or have db with devices - capacities) and then, based on % change, time interval and voltage You could probably do approx calc of the consumption. – sandrstar Sep 25 '12 at 14:42