Android get charge rate in milliamps via sysfs
Asked Answered
H

2

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?

Hamza answered 3/4, 2016 at 0:13 Comment(2)
Anyone? I can post these file names and contents if it would help. Was hoping to hear from someone who's done this before.Hamza
You may take a look for this #2440119Hasten
L
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

Libbie answered 15/4, 2016 at 2:53 Comment(3)
This appears to be the same value as read from file in accepted answer. Good to know though.Hamza
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.Libbie
Ah I see I missed that part. I apologize this should have received the bounty.Hamza
S
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.

Skunk answered 11/4, 2016 at 8:42 Comment(1)
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?Hamza
L
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

Libbie answered 15/4, 2016 at 2:53 Comment(3)
This appears to be the same value as read from file in accepted answer. Good to know though.Hamza
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.Libbie
Ah I see I missed that part. I apologize this should have received the bounty.Hamza

© 2022 - 2024 — McMap. All rights reserved.