How to lock Android screen via ADB?

PurpleDiane picture PurpleDiane · Dec 13, 2012 · Viewed 53.4k times · Source

Is there a way to lock the Android screen via the ADB?

I find ways to lock the display in an apk, but I want to lock the screen from the PC via ADB, to simulate a display timeout, without having to wait for the timeout.

Is it possible to do this?

Thanks, Diane

Answer

PurpleDiane picture PurpleDiane · Dec 13, 2012

Cool, I just found KEYCODE_POWER which is 26.

so it works by sending:

adb shell input keyevent 26

which locks the screen if the screen is unlocked. If the screen is already locked, it wakes up the device.

My guess is that the only way to ensure that the screen is locked (off), is to unlock (we use keyevent 82 (menu), then lock it with the power button keyevent. Does anyone have any idea if this is true?