Obtain screen status using ADB

2019-02-17 02:55发布

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?

标签: android adb
3条回答
不美不萌又怎样
2楼-- · 2019-02-17 03:15

dumpsys power | grep mScreenOn

查看更多
We Are One
3楼-- · 2019-02-17 03:15

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.

查看更多
狗以群分
4楼-- · 2019-02-17 03:33

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

Display Power: state=OFF

or

Display Power: state=ON
查看更多
登录 后发表回答