打开设备上的屏幕

发布于 2024-12-06 20:31:26 字数 247 浏览 2 评论 0原文

如何打开屏幕?

我尝试了这样的方法

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

泡沫很甜 2024-12-13 20:31:27

打开/关闭屏幕的命令是:

adb shell input keyevent 26

此压缩命令是首选,因为它允许您在脚本中使用它。

干杯!

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!

渔村楼浪 2024-12-13 20:31:27

这适用于 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

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
绝對不後悔。 2024-12-13 20:31:26
adb shell input keyevent KEYCODE_POWER

用于打开屏幕(当显示屏关闭时)
用于关闭屏幕(当显示器打开/唤醒时)

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)

兰花执着 2024-12-13 20:31:26

对于 Android 5.0 及以上版本:

adb shell input keyevent KEYCODE_WAKEUP

adb shell input keyevent 224
KEYCODE_WAKEUP

按键代码常量:唤醒键。唤醒设备。行为有点像KEYCODE_POWER,但如果设备已经唤醒,则没有任何效果。

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


注意:KEYCODE_POWER 已在 API 级别 1 中添加,而 KEYCODE_WAKEUP 已在 API 级别中添加20!

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!

海夕 2024-12-13 20:31:26

如果您愿意,可以打开/关闭它:

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

这在某些 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:

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

梦明 2024-12-13 20:31:26

我可能是错的,但是...

您不应该将广播视为发送以完成工作的东西,而是将它们视为在事情发生时发送的东西完成。

我认为当屏幕打开时系统会发送“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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文