Turn on screen on device

怎甘沉沦 提交于 2019-11-30 17:33:50
Gallal

I could be wrong about this, but...

You shouldn't think of broadcasts as something to send to get things done, but instead think of them as things that are sent when things are done.

I think the system sends 'android.intent.action.SCREEN_ON' when screen is goes on, but sending 'android.intent.action.SCREEN_ON' does not necessarily make the screen go on.

I hope this makes sense.

For the answer, you can find it in...

adb shell input keyevent KEYCODE_POWER

Works to turn on screen (when display is off) Works to turn off screen (when display is on/awake)

For Android 5.0 and above:

adb shell input keyevent KEYCODE_WAKEUP

or

adb shell input keyevent 224

Reference:

Wakes up the device. Behaves somewhat like KEYCODE_POWER but it has no effect if the device is already awake.


Note: KEYCODE_POWER added in API level 1 while KEYCODE_WAKEUP added in API level 20!

u can turn it on/off if u do like:

adb shell
@shell: input keyevent 26
@shell: (enter or via hidden command empty line)
@shell: exit

this worked for me on some android versions ;)
(NOTE: this will turn the screen on and off, depends on the actual screen state)

To detect the current state of the screen u can use the following ways:
Android < 5.x.x
adb shell dumpsys input_method
In the output search for mScreenOn=true/false

Android >= 5.x.x
adb shell dumpsys display
In the output search for mScreenState=ON/OFF

In my scripts i use this \s{0,}mScreen(State|On)=(?<STATE>(true|false|on|off))\s{0,} (Compiled|IgnoreCase|ExplicitCapture) regular expression for both outputs to detect the current state.

EDIT (16.03.2018):

There is also another way to detect the screen state, it works since Android 3.0. The dumpsys window policy command will give us all we need. - In the output search for mScreenOn(Fully)?=(?<STATE>(true|false)). There are also other useful informations like:

  • mUnrestrictedScreen (value is like: (0,0) 768x1280)
  • mRestrictedScreen (value is like: (0,0) 768x1184)

Regards,

k1ll3r8e

The command to toggle the screen on/off is:

adb shell input keyevent 26

This condensed command is preferred because it allows you to use it in scripts.

Cheers!

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