Obtain screen status using ADB

2019-02-17 03:25发布

问题:

I need to know in my script whether or not the device's screen is off. Is there any simple command to obtain such information using ADB?

回答1:

dumpsys power | grep mScreenOn



回答2:

On 5.0 it looks like you have to grep the dumpsys power output for

Display Power: state=OFF

or

Display Power: state=ON


回答3:

On Moto G5+, Moto X4, and Samsung Note 8 I'm seeing the following to work whereas dumpsys power did not (all devices are Marshmallow or later):

adb shell dumpsys deviceidle | grep mScreenOn

yields,

mScreenOn=false

when the screen is 'locked' whether blank or not, whereas,

adb shell dumpsys window | grep mScreenOn

yeilds,

mScreenOnEarly=false mScreenOnFully=false

only if the screen is not 'breathing' info such as the time.

Use dumpsys deviceidle to know if the screen needs to be unlocked to allow user interaction.



标签: android adb