10

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
  • 7,772
  • 4
  • 21
  • 31

2 Answers2

6

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,094
  • 1
  • 16
  • 31
  • 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
1

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,253
  • 3
  • 21
  • 52
  • 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