Termux:API Documentation

repository·master·Indexed 26 days ago

https://github.com/termux/termux-api

An Android application that exposes Android system APIs to the Termux terminal environment. It allows users to interact with hardware and system features via command-line tools, client scripts, and a helper binary that communicates with the TermuxApiReceiver broadcast receiver.

Tokens
494
Snippets
1
Records
3
Agent score
38%

What's inside Termux:API

  1. Use the termux-api helper binary

    master

    The termux-api client binary (provided in the termux-api package) acts as the bridge between the command line and the Android API. It uses Linux anonymous namespace sockets to communicate with the TermuxApiReceiver broadcast receiver.

    Standard communication follows this pattern:

    1. The termux-api binary generates two sockets (input and output).
    2. It passes these socket addresses to the Android system via an am broadcast command.
    3. stdin is forwarded from the binary to the API class, and the API class's output is forwarded to the binary's stdout.
    /system/bin/am broadcast ${BROADCAST_RECEIVER} --es socket_input ${INPUT_SOCKET} --es socket_output ${OUTPUT_SOCKET}
  2. Install the Termux:API application

    master

    To use Android APIs from the command line, you must install the Termux:API application on your Android device.

    Important Requirements:

    • The Termux:API app must be signed with the same key as your main Termux application for permissions to function. Only the main Termux app is permitted to call the API methods.
    • If you switch installation sources (e.g., moving from F-Droid to a debug build), you must uninstall the main Termux application and all currently installed plugins first.

    Installation Sources:

    • Stable: Obtain the latest version (currently v0.53.0) from F-Droid.
    • Debug/Latest Features: Per-commit debug builds are available via GitHub Actions.
  3. Use client scripts for API calls

    master
    While you can interact with the termux-api helper binary directly, it is recommended to use the client scripts available in the termux-api package. These scripts process command-line arguments into a format the helper binary understands, making it easier to invoke specific Android features.