Skip to content

Latest commit

 

History

History
155 lines (116 loc) · 2.88 KB

README.md

File metadata and controls

155 lines (116 loc) · 2.88 KB

Introduction

This module aims to provide functional and simple ADB commands to control an Android device from code (externally).

Installation

Install via pip:

pip install os-android-adb-handler

Usage and examples:

  • Make sure you have adb installed and an Android device connected.

Then just import the module and use it like so:

from os_android_adb_handler import adb_handler

# install an apk
adb_handler.install_apk(apk_path='path/to/apk/file.apk')

# start an app
adb_handler.start_app(package_name='com.osapps.pacakge', path_to_first_activity='startup.MainActivity')

# wait a bit for the app execution
time.sleep(7)

# go right
adb_handler.dpad_right()

# go up
adb_handler.dpad_up()

# take a screen shot
adb_handler.take_ss('path/to/ss1.png')

# go right
adb_handler.dpad_right()

# click enter
adb_handler.enter()

# take another ss
adb_handler.take_ss('path/to/second/ss2.png')

# send a shell command
adb_handler.send_shell(command='run something')

# send a custom key events
from os_android_adb_handler import key_events
adb_handler.key_event(key_events.KEYCODE_F)
adb_handler.key_event(key_events.KEYCODE_U)
adb_handler.key_event(key_events.KEYCODE_C)
adb_handler.key_event(key_events.KEYCODE_K)
adb_handler.key_event(key_events.KEYCODE_DEL)

# remove an app
adb_handler.uninstall_app(package_name='com.osapps.pacakge')

Function signatures

def start_app(package_name, path_to_first_activity):
    """
    Will start an already installed App in the device.

    Args:
        package_name: The app's package name
        path_to_first_activity: The relative path to the first activity (like main.MainActivity)
    """

def take_ss(ss_file_path):
    """
    Will take a screen shot.

    Args:
        ss_file_path: The destination path of the screen shot (file name, incl extension)
    """

def install_apk(apk_path):
    """
    Will install an APK file.

    Args:
        apk_path: The path to your APK file.
    """

def uninstall_app(package_name):
    """
    Will uninstall an app.

    Args:
        package_name: The app's package name
    """

def go_back():
    """
    Will navigate back
    """

def enter():
    """
    Will click the Enter key
    """

def dpad_right():
    """
    Will click the Right key
    """

def dpad_left():
    """
    Will click the Left key
    """

def dpad_up():
    """
    Will click the Up key
    """

def dpad_down():
    """
    Will click the Down key
    """

def key_event(key):
    """
    Will send a key event.
    
    Args:
        key: The key you want to send. You can use of the key_events keys
    """

def send_input(event):
    """
    Will send an input event
    """

def send_shell(command):
    """
    Will send a shell command
    """

def adb(command):
    """
    Will send an adb command
    """

.....

Licence

MIT