Skip to main content

Control android with python

Project description

PyDroidCTRL

The Android Device Controller is a Python-based utility for controlling and interacting with Android devices via ADB. This project provides a convenient set of tools for automating tasks such as taking screenshots, simulating touch gestures, typing text, streaming the device's screen to your computer, and retrieving detailed device information.

Features

  • Retrieve Device Information: Get detailed information about the connected Android device.
  • Execute Shell Commands: Run shell commands directly on the device.
  • Screenshot: Capture and save the current screen of the Android device.
  • Tap: Simulate a tap on the device screen at specified coordinates.
  • Swipe: Simulate a swipe gesture on the device screen from a start to an end point.
  • Type Text: Simulate typing text on the device.
  • Stream: Stream the Android device's screen to your computer using scrcpy (now fully asynchronous).

Requirements

  • Python 3.x
  • ADB (Android Debug Bridge)
  • scrcpy (for streaming the device's screen, optional)

Installation

  1. Clone the repository:

    pip install PyDroidCTRL
    cd android_controller
    
  2. Install required dependencies (if any):

    pip install -r requirements.txt
    
  3. Ensure ADB is installed and accessible from your system's PATH. You can download ADB from the official Android website.

  4. Ensure scrcpy is installed for screen streaming functionality. You can find installation instructions for scrcpy here.

Usage

Create an instance of the Controller class with the path to the ADB executable. Then use the provided methods to interact with the device.

Example

import os
import asyncio
from android_controller import Controller

# Define paths to the adb and scrcpy executables
adb_path = os.path.join(os.path.abspath('.'), "assets", "adb.exe")
scrcpy_path = os.path.join(os.path.abspath('.'), "assets", "scrcpy.exe")

async def main():
    # Initialize the controller with the paths to adb and scrcpy executables
    controller = Controller(adb_path=adb_path, scrcpy_path=scrcpy_path)

    # Retrieve and display device information
    device = controller.getDevice()
    print(device)

    # Simulate a swipe to the home menu
    controller.swipe(
        start=(device.width // 2, device.height - 1),
        end=(device.width // 2, (device.height // 16) * 15),
        duration=50
    )
    
    # Add a slight delay between gestures
    await asyncio.sleep(0.25)

    controller.swipe(
        start=(device.width // 2, (device.height // 5) * 3),
        end=(device.width // 2, (device.height // 5) * 2),
        duration=100
    )

    # Tap on the search bar and type text
    await asyncio.sleep(0.25)
    controller.tap((device.width // 2, device.height // 14))
    await asyncio.sleep(0.25)
    controller.type_text("Hello, World!")

    # Take a screenshot and save it to a file
    screenshot_path = "scr.png"
    controller.screenshot(screenshot_path)
    print(f"Screenshot saved to {screenshot_path}")

    # Stream the device's screen to your computer
    await controller.stream(max_fps=30, bit_rate="8M", rotate=False, always_on_top=True, disable_screensaver=True, no_audio=True)

# Run the main function using asyncio
asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydroidctrl-1.2.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyDroidCTRL-1.2.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pydroidctrl-1.2.1.tar.gz.

File metadata

  • Download URL: pydroidctrl-1.2.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pydroidctrl-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6610abf106356bd3915ff23e7e8254b5d976f181aa79bee06324e5771780ffe7
MD5 07bcb381af368e7ee573c764fb59e4e5
BLAKE2b-256 4dd61a93e9b0a08d42beeeef380d22ed1544945808ab75aa54b8d205970fbc73

See more details on using hashes here.

File details

Details for the file PyDroidCTRL-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: PyDroidCTRL-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for PyDroidCTRL-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c8a23bf1acdad531720c5556484836141b366623811d156e7056978b48622bc4
MD5 6085e6044351abeb13f5520807789e43
BLAKE2b-256 83a122b88d59a787ed876babc91eff49d2d5fe7309835acda33391e7e9780850

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page