DEV Community


Posted on

Automate Android with Python

Android phones can be controlled through Python scripts. To do so, adb must be installed and the phone connected.

Then you can use adb shell commands to control the phone like

import os


os.system("adb shell input tap 350 715")

which will click on the screen. You can also type text

os.system('adb shell input text "insert%syour%stext%shere"')

combined with time.sleep(seconds) you can automate any android app. Keeping in mind you don't have to use the phone at the same time.


You can wrap it around functions to make it easy. Connect your device with a usb cable, type

adb usb

Then run the script below in your favorite chat program

import os

def android_tap(x,y):
    os.system("adb shell input tap " + x + " " + y)

def android_type(text):
    os.system('adb shell input text "' + text + '"')


The program adb can do a lot more, a wrapper like this makes your android phone scriptable

Learn Python:

Top comments (0)