如何使用adb命令打开和关闭屏幕

如何使用adb命令打开和关闭屏幕

本文介绍了如何使用adb命令打开和关闭屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用KEYCODE_POWER打开和关闭我已扎根的电话。在以下两种情况下,都使用风箱命令打开和关闭屏幕。

I am using KEYCODE_POWER to turn on and turn off my rooted phone. The bellow command is used in both case turn on and turn off the screen.

adb shell input keyevent KEYCODE_POWER

但是,我想在单独的情况下使用它:打开和关闭。我有两个功能:打开和关闭功能。如果屏幕关闭并且我调用了打开功能,它将打开屏幕。如果屏幕已经打开,则打开功能将无法执行任何操作。否则,如果屏幕打开,我将调用关闭功能,然后它将关闭。

However, I want to use it in separated cases: turn on and turn off. I have two functions: turn on and turn off functions. If the screen is off and I call the turn on function, it will turn on the screen. if the screen is already turn on, the turn on function will not do anything. Otherwise, If the screen is on, I will call turn off function and it will turn off.

我尝试检查屏幕状态,但是效果不佳。实际上,与手机处理相比,屏幕状态更新太慢了。我还使用其他方法,但是这些方法使屏幕不睡觉就唤醒。

I tried to check the screen state but it does not work well. Actually, the screen state update is so slow comparison with processing of phone. I also use other way but these ways make the screen wakeup without sleep.

final Window win = getWindow();
    win.addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );

第二种方式:

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
wl.acquire();


推荐答案

adb shell输入keyevent 26

adb shell input keyevent 26

26-是设备上的按键事件代码电源按钮。

26 - is the keyevent code power button on the device.

您可以通过链接找到更多命令:

You can find more command by link : http://adbshell.com/commands

这篇关于如何使用adb命令打开和关闭屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:42