Overview
This guide explains how to unlock Android devices before starting an Appium session to help avoid application installation failures caused by locked device screens.
Prerequisites
Before unlocking the device, ensure the following:
ADB is installed and accessible.
The Android device is connected successfully.
Appium execution environment is configured.
Steps
Step 1: Unlock Android Device Before Appium Session
The issue may occur if the device screen is locked during the installation process.
To prevent this, unlock the device screen before the Appium session starts.
Java Example
Add the following method in your Java implementation:
public void unlockPixelScreen() throws IOException, InterruptedException {// Wake up the deviceRuntime.getRuntime().exec("adb shell input keyevent KEYCODE_WAKEUP");Thread.sleep(1000); // Unlock the screen (simulate swipe up/unlock key event)Runtime.getRuntime().exec("adb shell input keyevent 82");Thread.sleep(1000);}
Ruby Example
Add the following method in your Ruby implementation:
def unlock_pixel_screen# Wake up the devicesystem("adb shell input keyevent KEYCODE_WAKEUP")sleep(1)# Unlock the screen (simulate swipe up / unlock)system("adb shell input keyevent 82")sleep(1)end
Shell / CI Script Example
Run the following commands before Appium execution:
adb shell input keyevent KEYCODE_WAKEUPadb shell input keyevent 82
Outcome
After completing these steps:
The Android device screen will be unlocked before Appium execution.
Application installation failures caused by locked screens can be avoided.
Still have a question?
Support Contact:
support@testgrid.io
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article