18

How can I turn the sceen on ?

I tried something like this

adb -d  shell am broadcast -a android.intent.action.SCREEN_ON

It really should work, I send broadcast intent it is received by the system, but the screen doesn't turn on

I do not understand what is the problem, is it possible to turn the screen of the device by code ? I mean with software ? Cause it seems like the turning on of the screen is done just by the hardware button press . . . at least I got that felling , am I wrong ?

Lukap
  • 31,523
  • 64
  • 157
  • 244
  • 1
    This looks like a duplicate of this one if i'm not mistaken : http://stackoverflow.com/questions/2891337/turning-on-screen-programmatically – Sephy Sep 28 '11 at 15:32
  • Just for reference: if you use `adb shell am start -n packagename/activityname` to launch an app via adb, the screen will be turned on automatically if it's currently off (Tested on Android 5.0 with a Unity3d app) – Lena Schimmel Nov 21 '17 at 14:59
  • Check this answer: https://stackoverflow.com/a/49650552/3806413 – 0xAliHn Apr 04 '18 at 12:05

6 Answers6

33
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)

Grayson Henry
  • 834
  • 3
  • 11
  • 22
23

For Android 5.0 and above:

adb shell input keyevent KEYCODE_WAKEUP

or

adb shell input keyevent 224
KEYCODE_WAKEUP

Key code constant: Wakeup key. Wakes up the device. Behaves somewhat like KEYCODE_POWER but it has no effect if the device is already awake.

https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_WAKEUP


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

Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
14

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

k1ll3r8e
  • 729
  • 16
  • 22
6

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...

Community
  • 1
  • 1
Gallal
  • 4,267
  • 6
  • 38
  • 61
2

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!

AggieBlue
  • 534
  • 5
  • 11
  • 1
    Toggle ist not equal "turn on", turn on must take into account if the display is already on or not, otherwise it may be turned off. – David Oct 18 '16 at 11:58
1

this works in android 12

#!/bin/bash
screenState=$(adb shell dumpsys window policy | grep screenState=SCREEN_STATE_ | cut -c 32-)

if [ "$screenState" == "OFF" ]; then 
    adb shell input keyevent KEYCODE_POWER

fi
pwopow
  • 11
  • 3