11

I am developing a informational android app where I want to read the charge rate in milli-amps when the device is charging. I have seen other apps that can do this such as Ampere.

I believe the info should be in directory /sys/class/power_supply/battery which of these files are relevant in accomplishing this, and how could I calculate charge rate in mA from this?

rosghub
  • 8,924
  • 4
  • 24
  • 37
  • Anyone? I can post these file names and contents if it would help. Was hoping to hear from someone who's done this before. – rosghub Apr 03 '16 at 21:40
  • You may take a look for this http://stackoverflow.com/questions/2439619/getting-the-battery-current-values-for-the-android-phone – Maytham Fahmi Apr 11 '16 at 08:51

2 Answers2

8

According to the linux kernel doc, you can read the charge rate from /sys/class/power_supply/battery/current_now. The value is in µA, so you should scale it by 1000. Negative values mean that the device is charging.

SpaceBison
  • 2,525
  • 1
  • 21
  • 38
  • Tested this today, this value seems to be accurate but the value doesn't become negative until 20-30 seconds after I begin charging the device. And then when unplugging the device it stays negative for 20-30 seconds before becoming positive. Is this normal? – rosghub Apr 13 '16 at 21:33
2

directory may change according to the phone manufacturer. See this link for supporting more devices currentwidget

And above API 21+ charge counter and energy counter is implemented: see the doc

ugur
  • 3,604
  • 3
  • 26
  • 57
  • This appears to be the same value as read from file in accepted answer. Good to know though. – rosghub Apr 18 '16 at 07:25
  • sure but as i know the current value file is not the same for all devices. That is why many cases were implemented in the currentwidget app to support almost all devices. – ugur Apr 18 '16 at 09:30
  • Ah I see I missed that part. I apologize this should have received the bounty. – rosghub Apr 18 '16 at 19:28