Shoaib Akhtar
Shoaib Akhtar

Reputation: 1403

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

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?

Upvotes: -1

Views: 356

Answers (1)

Robert
Robert

Reputation: 42754

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.

Upvotes: 0

Related Questions