【问题标题】:How to verify android device Screen ON or OFF using adb shell command如何使用 adb shell 命令验证 android 设备屏幕打开或关闭
【发布时间】:2015-08-04 19:46:16
【问题描述】:

尝试使用mScreenOn=truemPowerState=SCREEN_BRIGHT_BIT 检查设备屏幕的开启或关闭。但以下命令不适用于最新的 android 版本。它什么也没返回

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

  1. 使用输入法转储系统

    adb shell dumpsys input_method | grep mScreenOn

  2. 使用电源转储系统

    adb shell dumpsys power | grep mScreenOn

    adb shell dumpsys power | grep mPowerState

在最新的 android 版本(Lollipop、Nougat、Oreo、Pie 等)上使用 adb shell 命令验证屏幕关闭或打开状态是否有任何其他方法

【问题讨论】:

    标签: android android-5.0-lollipop android-8.0-oreo android-7.0-nougat android-9.0-pie


    【解决方案1】:

    android - Obtain screen status using ADB - Stack Overflow的答案,复制到这里:

    • 我的手机:XiaoMi 9
      • 安卓:10

    使用 adb 检查屏幕状态 ON/OFF 吗?

    方法一:使用mHoldingDisplaySuspendBlocker

    • 命令:adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker
    • 输出:
      • mHoldingDisplaySuspendBlocker=false -> 屏幕关闭
      • mHoldingDisplaySuspendBlocker=true -> 屏幕开启

    方法二:使用mWakefulness

    • 命令:adb shell dumpsys power | grep mWakefulness=
    • 输出:
      • mWakefulness=Dozing -> 屏幕关闭
      • mWakefulness=Awake -> 屏幕开启

    方法3:使用nfc(如果android有NFC模块)

    • 命令:adb shell dumpsys nfc | grep mScreenState=
    • 输出:
      • mScreenState=OFF_LOCKED -> 屏幕关闭(并锁定)
      • mScreenState=ON_XXX -> 屏幕开启
        • mScreenState=ON_LOCKED -> 屏幕开启(并且锁定
        • mScreenState=ON_UNLOCKED -> 屏幕开启(并且解锁

    方法四:使用service call

    • 命令:adb shell service call power 12
    • 输出:
      • Result: Parcel(00000000 00000000 '........') -> 0 表示屏幕关闭
      • Result: Parcel(00000000 00000001 '........') -> 1 表示屏幕开启

    【讨论】:

      【解决方案2】:

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

      dumpsys input_method 中的 mInteractive 值将是“true”,用于显示开启,“false”用于显示关闭。

      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
      

      【讨论】:

        【解决方案3】:

        Android 5.0.1 – Lollipop 行为发生了变化,他们删除了日志记录 mScreenOn

        试了很多次,对比dumpsys input_method文件发现

        adb shell dumpsys input_method | grep -i mActive
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-23
          • 2015-07-26
          • 1970-01-01
          • 1970-01-01
          • 2019-03-18
          • 1970-01-01
          相关资源
          最近更新 更多