尝试使用
mScreenOn=true
或 mPowerState=SCREEN_BRIGHT_BIT
检查设备屏幕打开或关闭。但以下命令在最新的 Android 版本中不起作用。它什么也没返回
以下命令在 Android - 4.3 Jelly Bean 中运行良好
使用input_method dumpsys
adb shell dumpsys input_method | grep mScreenOn
使用电源转储系统
adb shell dumpsys power | grep mScreenOn
或
adb shell dumpsys power | grep mPowerState
有没有其他方法可以在最新的 Android 版本(Lollipop、Nougat、Oreo、Pie 等)上使用 adb shell 命令来验证屏幕关闭或打开状态
最近我遇到了同样的问题并找到了以下解决方案。
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
有 android - 使用 ADB 获取屏幕状态 - Stack Overflow 的答案,并复制到此处:
XiaoMi 9
10
mHoldingDisplaySuspendBlocker
adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker
mHoldingDisplaySuspendBlocker=false
-> 屏幕 关闭mHoldingDisplaySuspendBlocker=true
-> 屏幕ONmWakefulness
adb shell dumpsys power | grep mWakefulness=
mWakefulness=Dozing
-> 屏幕 关闭mWakefulness=Awake
-> 屏幕ONnfc
(如果安卓有NFC模块)adb shell dumpsys nfc | grep mScreenState=
mScreenState=OFF_LOCKED
-> 屏幕关闭(并锁定)mScreenState=ON_XXX
-> 屏幕ON
mScreenState=ON_LOCKED
-> 屏幕开启(且锁定)mScreenState=ON_UNLOCKED
-> 屏幕开启(且解锁)service call
adb shell service call power 12
Result: Parcel(00000000 00000000 '........')
-> 0
表示屏幕 OFFResult: Parcel(00000000 00000001 '........')
-> 1
表示屏幕ONAndroid 5.0.1 – Lollipop 行为发生了变化,他们删除了 mScreenOn 日志记录
尝试了很多次,对比dumpsys input_method文件才发现
adb shell dumpsys input_method | grep -i mActive
NFC API 为您提供了一些选项来了解屏幕是否打开或关闭以及是否锁定,在我这边我使用返回屏幕状态的 adb shell 命令:
adb shell dumpsys nfc | grep -e 'mScreenState=' -e 'Screen State:' | tr : = | cut -d '=' -f2
返回:ON_LOCKED或OFF_LOCKED或ON_UNLOCKED或OFF_UNLOCKED
注意: 某些设备具有 mScreenState 参数(如 Pixel 设备),其他设备具有屏幕状态参数(如 Galaxy Tab)