How to tell if screen is on with ADB [duplicate]

丶灬走出姿态 提交于 2019-12-05 22:10:02

问题


I am looking to find out whether or not it is possible to determine if the screen is on on an android device using ADB. I need to know this for some tests I am trying to run using monkey runner. Is there a shell command I can enter, and thus include as part of a monkey runner command, that will tell me definitively if the screen is on or off?


回答1:


In doing some testing I've found that using adb shell dumpsys power | grep mScreenOn will work on devices that have a version number of 4.2+

The command that I have found to work on all devices I have tested so far is to use:

 adb shell dumpsys input_method | grep mScreenOn

which will produce something like:

mSystemReady=true mScreenOn=true

which you can use to determine if the screen is on.

Tested on all Android Emulators in the range 2.2 - 4.4.2, Samsung Galaxy SII (4.0.4), Samsung Galaxy Tab 8.9 (4.0.4), and Nexus 4 with CM11

Also worth mentioning, on pre 4.2 devices you can use the command adb shell dumpsys power | grep mPowerState to get something like this:

mIsPowered=true mPowerState=3 mScreenOffTime=24970 ms
mPowerState=SCREEN_BRIGHT_BIT SCREEN_ON_BIT

and detect if the SCREEN_ON_BIT string is present




回答2:


Yes, if you enter:

 adb shell dumpsys power | grep mScreenOn

This will return a true or false value telling you whether or not the screen is currently on. It should look like this:

mScreenOn=true

Knowing this, all you need to do is parse the true/false value out of the result, and feed the shell command into a monkey runner script.

This was tested on an android device running 4.4.2.



来源:https://stackoverflow.com/questions/21409044/how-to-tell-if-screen-is-on-with-adb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!