问题
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 ?
回答1:
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...
- Calling hidden API in android to turn screen off
- turn the screen on/off in Android with a shake
回答2:
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)
回答3:
For Android 5.0 and above:
adb shell input keyevent KEYCODE_WAKEUP
or
adb shell input keyevent 224
Ref:
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!
回答4:
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.xadb shell dumpsys input_method
In the output search for mScreenOn=true/false
Android >= 5.x.xadb 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
回答5:
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!
来源:https://stackoverflow.com/questions/7585105/turn-on-screen-on-device