Search code examples
androidandroid-5.0-lollipopandroid-8.0-oreoandroid-7.0-nougatandroid-9.0-pie

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


Tried to check device Screen ON or OFF using mScreenOn=true or mPowerState=SCREEN_BRIGHT_BIT. But the following commands are NOT working in latest android versions. It is returning nothing

Following commands working fine in Android - 4.3 Jelly Bean

  1. using input_method dumpsys

    adb shell dumpsys input_method | grep mScreenOn

  2. using power dumpsys

    adb shell dumpsys power | grep mScreenOn or

    adb shell dumpsys power | grep mPowerState

is there any other way to verify the screen OFF or ON state using adb shell command on latest android versions (Lollipop, Nougat, Oreo, Pie,..etc)


Solution

  • Recently I had same problem and found out below solution.

    mInteractive value would be "true" in dumpsys input_method for display ON and "false" for display OFF.

    Ex usage in shell script:

    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