打开设备上的屏幕
如何打开屏幕?
我尝试了这样的方法
adb -d shell am broadcast -a android.intent.action.SCREEN_ON
它确实应该有效,我发送广播意图,它被系统接收,但屏幕没有打开
我不明白问题是什么,是否可以通过代码打开设备的屏幕?我的意思是用软件?因为看起来屏幕的打开只是通过按下硬件按钮来完成的。 。 。至少我有这样的感觉,我错了吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
打开/关闭屏幕的命令是:
此压缩命令是首选,因为它允许您在脚本中使用它。
干杯!
The command to toggle the screen on/off is:
This condensed command is preferred because it allows you to use it in scripts.
Cheers!
这适用于 Android 12
this works in android 12
用于打开屏幕(当显示屏关闭时)
用于关闭屏幕(当显示器打开/唤醒时)
Works to turn on screen (when display is off)
Works to turn off screen (when display is on/awake)
对于 Android 5.0 及以上版本:
或
https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_WAKEUP
注意:
KEYCODE_POWER
已在 API 级别 1 中添加,而KEYCODE_WAKEUP
已在 API 级别中添加20!For Android 5.0 and above:
or
https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_WAKEUP
Note:
KEYCODE_POWER
has been added in API level 1, whileKEYCODE_WAKEUP
has been added in API level 20!如果您愿意,可以打开/关闭它:
这在某些 Android 版本上对我有用;)
(注意:这将打开和关闭屏幕,取决于实际的屏幕状态)
检测当前的状态您可以通过以下方式使用屏幕:
Android < 5.xx
adb shell dumpsys input_method
在输出中搜索
mScreenOn=true/false
Android >= 5.xx
adb shell dumpsys display
在输出中搜索
mScreenState=ON/OFF
在我的脚本中我用这个
\s{0,}mScreen(State|On)=(?(true|false|on|off))\s{0,}
(Compiled|IgnoreCase|ExplicitCapture) 两个输出的正则表达式,用于检测当前状态。编辑(16.03.2018):
还有另一种检测屏幕状态的方法,它从 Android 3.0 开始工作。
dumpsys window policy
命令将为我们提供所需的一切。 - 在输出中搜索mScreenOn(Fully)?=(?(true|false))
。还有其他有用的信息,例如:
mUnrestrictedScreen
(值类似于:(0,0) 768x1280
)mRestrictedScreen
(值类似于:>(0,0) 768x1184
)问候,
k1ll3r8e
u can turn it on/off if u do like:
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 formScreenOn(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
我可能是错的,但是...
您不应该将广播视为发送以完成工作的东西,而是将它们视为在事情发生时发送的东西完成。
我认为当屏幕打开时系统会发送“android.intent.action.SCREEN_ON”,但发送“android.intent.action.SCREEN_ON”并不一定会使屏幕打开。
我希望这是有道理的。
对于答案,您可以在...
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...