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

问题描述 投票:0回答:4

尝试使用

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 版本(Lollipop、Nougat、Oreo、Pie 等)上使用 adb shell 命令来验证屏幕关闭或打开状态

android android-5.0-lollipop android-8.0-oreo android-7.0-nougat android-9.0-pie
4个回答
5
投票

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

mInteractive 值在 dumpsys input_method 中为“true”表示显示打开,“false”表示显示关闭。

Ex 在 shell 脚本中的用法:

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

4
投票

android - 使用 ADB 获取屏幕状态 - Stack Overflow 的答案,并复制到此处:

  • 我的电话:
    XiaoMi 9
    • 安卓:
      10

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

方法1:使用
mHoldingDisplaySuspendBlocker

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

方法2:使用
mWakefulness

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

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

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

方法4:使用
service call

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

3
投票

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

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

adb shell dumpsys input_method | grep -i mActive

0
投票

NFC API 为您提供了一些选项来了解屏幕是否打开或关闭以及是否锁定,在我这边我使用返回屏幕状态的 adb shell 命令:

adb shell dumpsys nfc | grep -e 'mScreenState=' -e 'Screen State:' | tr : = | cut -d '=' -f2

返回:ON_LOCKEDOFF_LOCKEDON_UNLOCKEDOFF_UNLOCKED

注意: 某些设备具有 mScreenState 参数(如 Pixel 设备),其他设备具有屏幕状态参数(如 Galaxy Tab)

© www.soinside.com 2019 - 2024. All rights reserved.