如何使用 adb shell 命令验证 android 设备屏幕开启或关闭

Lav*_*ham 1 android android-5.0-lollipop android-7.0-nougat android-8.0-oreo android-9.0-pie

尝试使用mScreenOn=true或来检查设备屏幕开启或关闭mPowerState=SCREEN_BRIGHT_BIT。但是以下命令在最新的 android 版本中不起作用。它什么都不返回

以下命令在 Android 中运行良好 - 4.3 Jelly Bean

  1. 使用 input_method dumpsys

    adb shell dumpsys input_method | grep mScreenOn

  2. 使用电源转储系统

    adb shell dumpsys power | grep mScreenOn 或者

    adb shell dumpsys power | grep mPowerState

有没有其他方法可以在最新的 android 版本(棒棒糖、牛轧糖、奥利奥、派等)上使用 adb shell 命令来验证屏幕关闭或打开状态

Sam*_*ath 5

最近我遇到了同样的问题,并找到了以下解决方案。

在 dumpsys input_method 中,mInteractive 值将是“true”,用于显示 ON 和“false”,用​​于显示 OFF。

在 shell 脚本中的 Ex 用法:

screen_info=`adb shell dumpsys input_method | grep mInteractive=true`
if [[ $screen_info == *"mInteractive"* ]]
then
    echo "Screen is ON"
     #Do something
else
    echo "Screen is OFF"
    #Do something
fi
Run Code Online (Sandbox Code Playgroud)