[英]How to set screen off on a rooted android device?
I have a rooted android device . 我有一个root用户设备。 I wish to set display off on it at a scheduled time.
我希望在预定的时间关闭它。
How can i set screen off programatically on that? 如何以编程方式设置屏幕? Can we do it using Linux commands?
我们可以使用Linux命令吗?
Thanks. 谢谢。
You can use, adb shell input keyevent
你可以使用,
adb shell input keyevent
Usage : 用法:
adb shell input keyevent [--longpress] <key code number or name>
To Turn your Screen off, use Keycode 要关闭屏幕,请使用Keycode
26 --> "KEYCODE_POWER"`
Run this from your prompt: 从提示符运行此命令:
root@user:/$ adb shell input keyevent 26
Or this, 或这个,
root@user:/$ adb shell input keyevent KEYCODE_POWER
Run the above command from your Function/Method : Execute ADB Command through Android Application . 从您的函数/方法运行以上命令: 通过Android应用程序执行ADB命令 。
This procedure works for a Non-rooted device too. 此过程也适用于非root设备。
Complete List of Events : See Here 完整的活动清单: 见这里
Setting up ADB : See Here 设置亚行: 见这里
For those with the same issue like me: I found on my MTK device following code to turn off the screen, because keyevent 26
doesn't work on my device: 对于那些像我一样有问题的人:我在我的MTK设备上找到了关闭屏幕的代码,因为
keyevent 26
在我的设备上不起作用:
adb shell input keyevent 6
adb shell输入keyevent 6
will turn off the devices screen also. 也将关闭设备屏幕。 To turn on the devices screen, you can do it with
keyevent 26
. 要打开设备屏幕,您可以使用
keyevent 26
执行此keyevent 26
。
The best way to find out which keyevent works for your device is with a tiny bash script like this: 找出哪个keyevent适用于您的设备的最佳方法是使用这样的小型bash脚本:
#!/bin/bash while do count=$(( $count+1 )) input keyevent $count echo "input keyevent $count" sleep 1 done
sleeping="$(adb shell dumpsys power | grep 'mWakefulness=')"
screen="$(adb shell dumpsys nfc| grep 'mScreenState=')"
case "$screen" in
"mScreenState=OFF")
echo "* Device is not unlocked."
;;
"mScreenState=ON_LOCKED")
echo "* Device is not unlocked."
sleep 0
exit ;;
"mScreenState=ON_UNLOCKED")
echo "* Locking screen.."
adb shell input keyevent 26
echo "* Screen turned off"
exit
esac
echo -e "$basename$0: internal error -- can't lock screen since it's not unlocked"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.