Mobile Development 9 min read

Automating Android Devices with Python and ADB

This guide explains how to set up ADB and Python libraries, enable USB debugging, and write Python scripts that control an Android phone to perform actions such as taking selfies, searching for word definitions, and capturing screenshots, providing a practical introduction to mobile automation.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Automating Android Devices with Python and ADB

Python can control almost any device, and this tutorial shows how to use Python code with the Android Debug Bridge (ADB) to automate actions on an Android phone.

Installation preparation : Install the ADB tool (bundled with Android Studio or from the official website) and the Python library pip install pure-python-adb # install pure-python-adb library. . Optionally install scrcpy to mirror and control the phone from the computer.

Enable USB debugging : Unlock developer options by tapping the build number seven times, then enable USB debugging in the developer options panel. Connect the phone to the PC via USB.

Connecting with Python : Start the ADB server with adb start-server . Use the pure-python-adb library to create an AdbClient object, list connected devices, and select the target device.

Script basics : Use shell commands to simulate touch events. Activate pointer location in developer options to see screen coordinates. The top‑left corner is (0,0); the bottom‑right corner gives the maximum x and y values.

Example 1 – Selfie timer : Import the library, connect to the device, launch the camera app, wait a few seconds, and trigger a photo capture. The script demonstrates opening an app, waiting, and sending a tap command.

Example 2 – Definition searcher : Open the default browser, tap the search bar at known coordinates (e.g., (440,200)), input a query, simulate the Enter key (event ID 66), wait, then capture a screenshot and save it as a PNG file.

Both examples illustrate how to combine ADB commands with Python to perform tasks that would normally require manual interaction, enabling powerful automation of Android devices.

By following these steps you can automate virtually any interaction with an Android device using Python and ADB.

mobile developmentPythonAndroidautomationscriptingADB
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.