Is it possible to get value for current battery level via ADB shell command?
Asked Answered
B

1

-1

With the below adb command I am able to get current battery level(as shown in image.

adb shell dumpsys battery | findstr /r /c:level

enter image description here

I am getting response as level: 12

Is there any way to get only value(ie 12 here) instead of level:12?

Bilingual answered 31/8, 2022 at 14:31 Comment(0)
G
0

You can simply use the commands available on Android to get the correct line and then get only the right side of the line:

adb shell "dumpsys battery | grep level | sed 's/^.* \(.*\)$/\1/' "

sed will output what is printed after the last space to the line end.

Gargan answered 31/8, 2022 at 16:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.