尝试使用mScreenOn=true
或mPowerState=SCREEN_BRIGHT_BIT
检查设备屏幕的开启或关闭。但是以下命令在 Android 5.0.1 - Lollipop 中无效。什么都不回来
以下命令在Android中运行良好 - 4.3 Jelly Bean
使用input_method dumpsys
adb shell dumpsys input_method | grep mScreenOn
使用power dumpsys
adb shell dumpsys power | grep mScreenOn
或
adb shell dumpsys power | grep mPowerState
还有其他方法可以在Lollipop中使用adb shell命令验证屏幕关闭或开启状态
答案 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
10
mHoldingDisplaySuspendBlocker
adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker
mHoldingDisplaySuspendBlocker=false
->屏幕关闭 mHoldingDisplaySuspendBlocker=true
->屏幕打开 mWakefulness
adb shell dumpsys power | grep mWakefulness=
mWakefulness=Dozing
->屏幕关闭 mWakefulness=Awake
->屏幕打开 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
表示屏幕 ON