簡體   English   中英

如何使用 adb shell 命令驗證 android 設備屏幕開啟或關閉

[英]How to verify android device Screen ON or OFF using adb shell command

嘗試使用mScreenOn=truemPowerState=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 mScreenOn

    adb shell dumpsys power | grep mPowerState

有沒有其他方法可以在最新的 android 版本(棒棒糖、牛軋糖、奧利奧、派等)上使用 adb shell 命令來驗證屏幕關閉或打開狀態

最近我遇到了同樣的問題,並找到了以下解決方案。

在 dumpsys input_method 中,mInteractive 值將是“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

Android 5.0.1 – Lollipop 的行為改變了,他們刪除了記錄 mScreenOn

試了很多次,對比dumpsys input_method文件后發現

adb shell dumpsys input_method | grep -i mActive

android 的答案- 使用 ADB 獲取屏幕狀態 - 堆棧溢出,並復制到這里:

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

使用 adb 檢查屏幕狀態 ON/OFF ?

方法一:使用mHoldingDisplaySuspendBlocker

  • 命令: adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker
  • 輸出:
    • mHoldingDisplaySuspendBlocker=false -> 屏幕關閉
    • mHoldingDisplaySuspendBlocker=true -> 屏幕開啟

方法2:使用mWakefulness

  • 命令: adb shell dumpsys power | grep mWakefulness= adb shell dumpsys power | grep mWakefulness=
  • 輸出:
    • mWakefulness=Dozing -> 屏幕關閉
    • mWakefulness=Awake -> 屏幕開啟

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

  • 命令: adb shell dumpsys nfc | grep mScreenState= 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表示屏幕開啟

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM