Is it possible to fetch current battery level via ADB shell command?
Asked Answered
Y

2

0

Suppose If change the battery level to any desired value(say from current 50 to 20)

adb shell dumpsys battery set level 20

Now I want adb command to fetch the current battery level(ie 20).

With the below command I can reset to original value(50 in our example)

adb shell dumpsys battery reset

Now again I want fetch the current current charge level via adb command

Yuonneyup answered 30/8, 2022 at 11:50 Comment(0)
H
2

For linux/macOS:

 adb shell dumpsys battery | grep level

For Windows:

adb shell dumpsys battery | findstr /r /c:level
Helio answered 30/8, 2022 at 12:1 Comment(7)
Getting error with above command "grep' is not recognized as an internal or external command, operable program or batch file."Yuonneyup
What OS are you on? Windows/Linux/macOS ?Helio
I am using WindowsYuonneyup
try adb shell dumpsys battery | findstr /r /c:levelHelio
The easier solution would be to use grep of the Android phone: adb shell "dumpsys battery | grep level" As it bases on Linux the chance is very high that it has grep.Babyblueeyes
Yes it also worked.. adb shell "dumpsys battery | grep level" @BabyblueeyesYuonneyup
Is there any way to get only value say 50 instead of level:50? I have asked the question separately here, please reply #73558032Yuonneyup
G
0

You can read a file where level/capacity located

The file is located in /sys/class/power_supply/battery/capacity

In Linux, MacOS and Windows:

adb shell cat /sys/class/power_supply/battery/capacity

Gladis answered 6/5, 2024 at 22:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.