How to Unlock Android Devices Before Appium Execution

Modified on Mon, Jun 15 at 2:35 PM

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

  1. Add the following method in your Java implementation:

public void unlockPixelScreen() throws IOException, InterruptedException {    // Wake up the device    Runtime.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); }

Caption: Unlock Android device using Java

Ruby Example

  1. Add the following method in your Ruby implementation:

def unlock_pixel_screen  # Wake up the device  system("adb shell input keyevent KEYCODE_WAKEUP")  sleep(1)   # Unlock the screen (simulate swipe up / unlock)  system("adb shell input keyevent 82")  sleep(1) end

Caption: Unlock Android device using Ruby

Shell / CI Script Example

  1. Run the following commands before Appium execution:

adb shell input keyevent KEYCODE_WAKEUP adb shell input keyevent 82

Caption: Unlock Android device using shell commands


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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article