如何在“Android 5.0.1 - Lollipop”

时间:2015-05-22 17:26:37

标签: android android-5.0-lollipop

尝试使用mScreenOn=truemPowerState=SCREEN_BRIGHT_BIT检查设备屏幕的开启或关闭。但是以下命令在 Android 5.0.1 - Lollipop 中无效。什么都不回来

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

  1. 使用input_method dumpsys

    adb shell dumpsys input_method | grep mScreenOn

  2. 使用power dumpsys

    adb shell dumpsys power | grep mScreenOn                      或

    adb shell dumpsys power | grep mPowerState

  3. 还有其他方法可以在Lollipop中使用adb shell命令验证屏幕关闭或开启状态

3 个答案:

答案 0 :(得分:3)

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

mInteractive值在dumpsys input_method中为“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

答案 1 :(得分:1)

Android 5.0.1 - Lollipop的行为发生了变化,他们删除了记录mScreenOn

多次尝试并在比较dumpsys input_method文件后发现

adb shell dumpsys input_method | grep -i mActive

答案 2 :(得分:0)

已回答android - Obtain screen status using ADB - Stack Overflow,并复制到此处:

  • 我的电话:XiaoMi 9
    • Android:10

使用adb检查屏幕状态的开/关吗?

方法1:使用mHoldingDisplaySuspendBlocker

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

方法2:使用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->屏幕打开(和已解锁

方法4:使用service call

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