Termux:API Complete Guide — Control Your Android from Terminal (2026)



Termux · Android API · Automation

Termux:API Complete Guide — Control Your Android from Terminal (2026)

🆓 Free 🤖 No Root Required 📱 Android ✅ Tested 2026

// 01 — Introduction: what's Termux:API?

If you've been using Termux for a while, you've probably realized that it's not just a Linux terminal for your Android phone — it's a full-blown power tool Pretty simple, actually. But once you installTermux:API, everything changes. So termux:API is the bridge between your terminal and Android's core hardware and software features. To put it simply: with it, you can send SMS messages, take photos, read sensor data, make phone calls, control. Notifications, access your clipboard, and much more — all from the command line, with no root required.

This complete Termux:API guide is designed for everyone, whether you're brand new to Termux or. An experienced terminal user looking to automate your Android device at a deeper level. But by the time you finish this tutorial, you'll understand how Termux:API works, know all the. Major commands, and be able to write real automation scripts that interact with your phone's hardware.

Termux:API works by running a companion Android app in the background. In plain terms: this app listens for commands sent from your Termux terminal and executes them using Android's Java APIs. This means you get full access to things like the camera, GPS, accelerometer. So battery status, clipboard, and text-to-speech engine — all without ever leaving the terminal. No joke. But it's genuinely one of the most powerful features in the entire Termux environment, and it's completely free.

Rixon Xavier from HYDRA TERMUX has been exploring Termux tools since 2023, and Termux:API is consistently one of the most underused yet incredibly capable tools in any Android hacker's toolkit Not what you expected? Let me explain: whether you want to build a GPS logger, a motion-triggered camera script, an automated SMS responder. Or just want to toggle your flashlight from a bash script, this guide covers it all. Let's dive in.

Termux:API requires no root and works on standard Android devices running Android 7. 0 and above. Everything in this guide is legal, educational, and works on your own device.

// 02 — Installation: Termux:API App + Package Setup

Before you can use any Termux:API command, you need to do a two-part setup: install the Termux:API companion Android app, and then install the termux-api package inside Termux itself. Both parts are required. To put it simply: if you skip either one, your commands will throw errors or simply do nothing.

Step 1: Install the Termux:API Android App

The Termux:API app is a background service that acts as. The middleman between your terminal commands and Android's system APIs. Most people miss this. You must install this from theF-Droid app store, not the Google Play Store. The Play Store version of Termux is outdated and incompatible with newer packages. So using mismatched versions from different sources is one of the most common causes of Termux:API failures.

01

Install F-Droid

Download and install the F-Droid APK from f-droid. Org. This is a free and open-source app store that hosts the correct Termux builds.

02

Search for Termux:API

Open F-Droid, search for Termux:API, and install it.. Make sure you also have the main Termux app from F-Droid (not Play Store).

03

Grant Permissions

After installing, open the Termux:API app once. It may appear blank — that's normal. Then go to Android Settings → Apps → Termux:API and grant all relevant permissions: Camera, Location, Contacts, SMS, Microphone, etc.

Step 2: Install the termux-api Package Inside Termux

Now open your Termux terminal and run the following commands to update your package list and install the termux-api package:

bash copy
pkg update && pkg upgrade -y
pkg install termux-api -y

This installs all the termux-*command-line tools that communicate with the Termux:API background app. The package is small (under 1 MB) and installs quickly.

Step 3: Verify the Installation

To confirm everything is working, run a simple test command — get your device's battery status:

bash copy
termux-battery-status

If everything is installed correctly, you should see JSON output like this:

json copy
{ "health": "GOOD", "percentage": 87, "plugged": "UNPLUGGED", "status": "DISCHARGING", "temperature": 32. 0
}
💡
Tip: If you get a No such file or directory error, make sure the Termux:API app (from F-Droid) is installed AND open in the background. The app must be running for commands to work.

// 03 — Camera, Torch & Media Controls

One of the most exciting parts of Termux:API is the ability. But let me explain: to control your phone's camera and flashlight directly from a terminal command. A quick example: this opens the door to creative scripting — imagine a motion-sensor script that auto-snaps a photo, or a bash alarm that toggles your flashlight. So no third-party app required.

Taking a Photo from the Terminal

Use termux-camera-photo to capture a photo with either the front or rear camera. The image is saved to a path you specify.

bash copy
# Take a photo using the rear camera (camera ID 0) and save it
termux-camera-photo -c 0 /sdcard/photo. Jpg # Take a selfie with the front camera (camera ID 1)
termux-camera-photo -c 1 /sdcard/selfie. Jpg

The -c flag specifies the camera ID. But on most phones,0 is the rear camera and is the front-facing camera. Some phones with multiple lenses may have additional IDs like 2 or 3.

To list all available cameras on your device:

bash copy
termux-camera-info

This outputs a JSON array with each camera's ID, lens facing direction, and supported resolutions.

Controlling the Flashlight / Torch

Turning the torch on and off is one of the simplest Termux:API tricks — and one of the most satisfying:

bash copy
# Turn torch ON
termux-torch on # Turn torch OFF
termux-torch off. # Flash the torch 5 times (fun for scripts)
for i in {1. 5}; do termux-torch on sleep 0. 5 termux-torch off sleep 0. 5
done

Media Player Controls

Termux:API can also control Android's media playback — useful for automating music or audio playback from scripts:

bash copy
# Play a local audio file
termux-media-player play /sdcard/Music/track. Mp3 # Pause playback
termux-media-player pause # Get playback info (current track, position)
termux-media-player info # Stop playback
termux-media-player stop

Text-to-Speech (TTS)

Make your phone speak any text out loud using the built-in Android TTS engine:

bash copy
# Speak a sentence
termux-tts-speak "Hello! Termux is amazing.. " # Change speech rate (0. 5 = slow, 2. 0 = fast)
termux-tts-speak -r 0. 8 "This is spoken at a slower rate. " # List available TTS engines
termux-tts-engines
💡
Tip: Combine termux-tts-speak with a cron job to create a voice alarm or reminder system that announces the time on schedule.

// 04 — SMS, Calls & Contact Management

Termux:API gives you powerful control over your Android phone's communication features from the terminal. You can send SMS messages, list contacts, read your call log, and even initiate phone calls — all from bash scripts. So this is incredibly useful for automation, logging, and scripted workflows.

⚠️
Warning:Always use SMS and call features only on your own device. So and with full consent of all parties Worth asking yourself that. So think of it this way: misuse of communication features may violate laws in your country. So this guide is strictly for educational and personal automation purposes.

Sending an SMS Message

bash copy
# Send a basic SMS
termux-sms-send -n "+1234567890" "Hello from Termux! " # Send to multiple numbers at once
termux-sms-send -n "+1234567890,+0987654321" "Group message from terminal"

The -n flag takes the recipient's phone number.. You can pass multiple numbers separated by commas.. The message text follows as the last argument.

Reading Your SMS Inbox

You can list SMS messages from your inbox, sent box, or drafts:

bash copy
# List inbox messages (default: last 10)
termux-sms-list # Show only 5 messages from the inbox
termux-sms-list -l 5 -t inbox # Show sent messages
termux-sms-list -t sent # Show messages from a specific number
termux-sms-list -n "+1234567890"

The output is JSON, which you can pipe through jq for cleaner formatting. Install jq with pkg install jq.

bash copy
# Pretty-print SMS list using jq
termux-sms-list -l 5 | jq '. [] | {from:. Number, msg:. Body}'

Call Log and Contact List

bash copy
# View recent call log
termux-call-log -l 10 # List all contacts
termux-contact-list # Search contacts for a specific name
termux-contact-list | grep -i "john"

Making a Phone Call

bash copy
# Initiate a call to a number (opens dialer)
termux-telephony-call "+1234567890"

Note that this opens the Android dialer rather than placing the call silently. And think of it this way: you must tap the call. Button to confirm — this is by Android design for security reasons.

Clipboard Access

Reading and writing to Android's clipboard is one of the most commonly used Termux:API features:

bash copy
# Read current clipboard content
termux-clipboard-get # Set clipboard to a specific string
termux-clipboard-set "This text is now in your clipboard" # Copy command output directly to clipboard
echo "Hello World" | termux-clipboard-set

// 05 — Sensors, Location & Device Info

Your Android device is packed with sensors — accelerometer, gyroscope, magnetometer, light sensor, and more. Termux:API exposes all of these through simple terminal commands. Combined with GPS location data and device information, this section. Gives you everything you need to build sensor-aware automation scripts.

GPS Location

Getting your current GPS location is straightforward with Termux:API:

bash copy
# Get current GPS location (waits for a fix)
termux-location # Get location using network (faster, less accurate)
termux-location -p network # Get location once and exit quickly
termux-location -r once

Example output:

json copy
{ "latitude": 8. 5241, "longitude": 76. 9366, "altitude": 7. 0, "accuracy": 15. 234, "bearing": 0. 0, "speed": 0. 0 — "elapsedMs": 4321— "provider": "gps"
}

Reading Sensors

The termux-sensor command gives you access to all available hardware sensors:

bash copy
# List all available sensors on your device
termux-sensor -l # Read accelerometer data (3 samples)
termux-sensor -s "android. Sensor. Here's how it works: accelerometer" -n 3 # Read the light sensor once
termux-sensor -s "android. Sensor. Light" -n 1 # Continuously stream gyroscope data
termux-sensor -s "android.. Sensor. Gyroscope" -d 500

The -d flag sets the delay between readings in milliseconds.-n sets how many readings to take before exiting.

Battery Information

bash copy
# Detailed battery status
termux-battery-status # Extract just the percentage using jq
termux-battery-status | jq '. Percentage'

Device and Network Info

bash copy
# Check WiFi connection status
termux-wifi-connection-info # Scan for nearby WiFi networks
termux-wifi-scan-info # Get telephony/cellular info
termux-telephony-cell-info # Get SIM card device ID info
termux-telephony-device-info

Notifications

Sending custom Android notifications from the terminal is incredibly useful for scripts that need to alert you:

bash copy
# Send a basic notification
termux-notification --title "Script Done" --content "Your task completed successfully" # Notification with a custom ID (so you can update/remove it)
termux-notification --id 42 --title "GPS Log" --content "Location saved. " # Remove a notification by ID
termux-notification-remove 42 # Show a. Notification with high priority and vibration
termux-notification --priority high --title "Alert" --content "Check your device"
💡
Tip: Use termux-notification at the end of long-running scripts so your phone alerts you when they finish — even if your screen is off and Termux is in the background.

// 06 — Automation Scripts: Real-World Use Cases

Now that you know the core commands, let's put them together into real, practical automation scripts. And this is where Termux:API truly shines.. These scripts combine multiple API calls to create powerful workflows you. Can run from a single command or schedule with a cron job.

Script 1: GPS Location Logger

This script logs your GPS coordinates every 5 minutes to a file — perfect for tracking a route or creating a movement log:

bash copy
#! /data/data/com. Termux/files/usr/bin/bash
# GPS Logger Script — saves location every 5 minutes
LOGFILE="/sdcard/gps_log. Txt" while true; do TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") LOCATION=$(termux-location -p gps -r once) LAT=$(echo $LOCATION | jq '. Latitude') LON=$(echo $LOCATION | jq '. Longitude') echo "$TIMESTAMP | Lat: $LAT | Lon: $LON" >> $LOGFILE echo "Logged: $LAT, $LON" sleep 300 # wait 5 minutes
done

Script 2: Battery Alert Notifier

This script monitors your battery and sends a notification when it drops below 20%:

bash copy
#! /data/data/com. Termux/files/usr/bin/bash
# Battery Alert Script
THRESHOLD=20 while true; do LEVEL=$(termux-battery-status | jq '. Percentage') STATUS=$(termux-battery-status | jq -r '. Status') if [ "$LEVEL" -le "$THRESHOLD" ] && [ "$STATUS" = "DISCHARGING" ]; then termux-notification \ --title "⚠️ Low Battery Alert" \ --content "Battery is at ${LEVEL}% Worth asking yourself that. Please charge your phone! " \ --priority high termux-tts-speak "Warning! Battery level is ${LEVEL} percent. Please charge now.. " fi sleep 120 # check every 2 minutes
done

Script 3: Motion-Triggered Photo Capture

This script reads the accelerometer and takes a photo if significant movement is detected:

bash copy
#! /data/data/com. Termux/files/usr/bin/bash
# Motion-Triggered Camera Script
THRESHOLD=12 # acceleration threshold (m/s²)
PHOTODIR="/sdcard/MotionCam"
mkdir -p $PHOTODIR echo "Monitoring for motion. (Ctrl+C to stop)" while true; do DATA=$(termux-sensor -s "android. Sensor. Accelerometer" -n 1 2>/dev/null) X=$(echo $DATA | jq '. Values[0]' 2>/dev/null) Y=$(echo $DATA | jq '. Values[1]' 2>/dev/null) Z=$(echo $DATA | jq '. Values[2]' 2>/dev/null) MAGNITUDE=$(echo "sqrt($X*$X + $Y*$Y + $Z*$Z)" | bc -l 2>/dev/null) if (( $(echo "$MAGNITUDE > $THRESHOLD" | bc -l) )); then FILENAME="$PHOTODIR/motion_$(date +%H%M%S). Jpg" termux-camera-photo -c 0 "$FILENAME" termux-notification --title "📸 Motion Detected" --content "Photo saved: $FILENAME" echo "Motion! Photo saved: $FILENAME" sleep 3 # cooldown fi sleep 1
done

Script 4: Daily Morning Briefing

This script reads today's date, battery level, and WiFi status, then speaks a morning summary using TTS:

bash copy
#! /data/data/com. And termux/files/usr/bin/bash
# Morning Briefing Script
DATE=$(date "+%A, %B %d")
BATTERY=$(termux-battery-status | jq '. Percentage')
WIFI=$(termux-wifi-connection-info | jq -r '. Ssid // "not connected"') MESSAGE="Good morning! Today is $DATE. Your battery is at $BATTERY percent. You're connected to WiFi network: $WIFI. Have a great day! " termux-tts-speak "$MESSAGE"
termux-notification --title "☀️ Morning Briefing" --content "$MESSAGE"
Schedule the morning briefing script with Termux's cron daemon. And install it with pkg install cronie, then run crontab -e and add: 0 7 * * * bash /sdcard/morning. Sh to trigger it every day at 7 AM.

// 07 — Common Errors and Fixes

Error 1: "Permission denied" or no output

Cause: The Termux:API Android app doesn't have the required permissions granted.

Fix:Go to Android Settings → Apps → Termux:API → Permissions and.. Grant all permissions relevant to what you're trying to do (Camera — Location— SMS — Contacts— etc. ).

Error 2: "termux-api: command not found"

Cause: The termux-api package is not installed inside Termux.

Fix: Run pkg install termux-api inside Termux.

Error 3: Command runs but nothing happens

Cause: The Termux:API companion app is installed from Google Play Store (outdated) instead of F-Droid, OR the app is not running in the background.

Fix:Uninstall the Play Store version. Install Termux and Termux:API both from F-Droid.. Open the Termux:API app once to start the service.

Error 4: "termux-location" hangs and never returns

Cause:GPS signal is weak or unavailable indoors. Location permission not granted.

Fix: Use -p network instead of GPS for faster fixes. Make sure Location permission is granted to Termux:API.. Move to an area with better GPS signal..

bash copy
# Use network-based location instead of GPS
termux-location -p network -r once

Error 5: "termux-camera-photo" fails silently

Cause: Camera permission not granted to Termux:API, or another app is using the camera.

Fix:Grant Camera permission to Termux:API. But close any camera apps. Try specifying a different camera ID (-c 0 or -c 1).

Error 6: "jq: command not found"

Cause: The jq tool (used for parsing JSON output) is not installed.

Fix: pkg install jq

// 08 — Pro Tips for Power Users

💡
Tip 1 — Pipe to jq:Almost every Termux:API command outputs JSON. But install jq and pipe output into it for clean, readable results and easy field extraction.
💡
Tip 2 — Use Termux:Widget: Combine Termux:API scripts with the Termux:Widget app to add home screen shortcut buttons that trigger your scripts with one tap.
💡
Tip 3 — Automate with Tasker: Termux scripts you can trigger by Tasker events (like connecting to WiFi or receiving an SMS) using the Termux Tasker plugin, enabling incredibly powerful automations.
💡
Tip 4 — Keep the app alive:Android may kill background apps to save battery. So go to Settings → Battery → App Battery Management → Termux:API and set it to "No restrictions" so it stays running.
💡
Tip 5 — Use vibration for silent alerts: termux-vibrate -d 500vibrates the phone for 500ms.. Useful in scripts where you want a tactile notification without sound.
💡
Tip 6 — Check API docs anytime: Run termux-[command] --help or visit the official Termux wiki for the full flag reference for any command.

// 09 — Termux:API Command Reference Table

Command Category What It Does Root Required?
termux-battery-statusDeviceReturns battery level, health, temp, statusNo
termux-camera-photoCameraCaptures a photo with front or rear cameraNo
termux-camera-infoCameraLists available cameras and resolutionsNo
termux-clipboard-getClipboardReads Android clipboard contentNo
termux-clipboard-setClipboardWrites text to Android clipboardNo
termux-contact-listContactsLists all contacts in JSON formatNo
termux-call-logCallsShows recent call historyNo
termux-locationGPSReturns GPS or network-based coordinatesNo
termux-notificationNotificationsSends a custom Android notificationNo
termux-sensorSensorsReads accelerometer, gyro, light, etc.No
termux-sms-listSMSLists SMS inbox/sent messagesNo
termux-sms-sendSMSSends an SMS to a phone numberNo
termux-telephony-callCallsOpens dialer to call a numberNo
termux-torchHardwareToggles flashlight on/offNo
termux-tts-speakAudioSpeaks text aloud using Android TTSNo
termux-media-playerAudioPlay, pause, stop, info for audio filesNo
termux-vibrateHardwareVibrates the device for a set durationNo
termux-wifi-connection-infoNetworkShows current WiFi SSID, IP, signal infoNo
termux-wifi-scan-infoNetworkScans and lists nearby WiFi networksNo
termux-telephony-device-infoNetworkReturns device ID and network operator infoNo

// 10 — Frequently Asked Questions

Does Termux:API require root access?
No, Termux:API doesn't require root access at all. Let me explain: it works entirely through Android's official permission system via the companion app. You just need to grant the relevant permissions (Camera, SMS, Location, etc. ) in Android settings. All commands in this guide work without root on any standard Android device running Android 7. 0 or later.
Why does Termux:API not work even after installation?
The most common reason is a version mismatch. The Termux:API app and the Termux main app must both come from the. Same source — either both from F-Droid or both from the GitHub releases page. No joke. A quick example: never mix a Play Store version with an F-Droid version. Also make sure you've run pkg install termux-api inside Termux AND that permissions are granted in Android settings.
Can I use Termux:API for cybersecurity or penetration testing?
Termux:API itself is a device automation tool, not a hacking tool. And however, it you can combin with other Termux tools for legitimate security research on your own. Device — for example, logging GPS position, gathering device info, or automating tasks during authorized security assessments. Always stay within legal and ethical boundaries. And check out hydra termux.. Blogspot. Com for more guides on ethical cybersecurity tools in Termux.
what's the difference between termux-location -p gps and -p network?
The -p gps option uses your phone's GPS hardware for accurate positioning, but it requires a. Clear view of the sky and takes longer to get a fix. The-p network option uses cell towers and WiFi to estimate your location —. It's much faster and works indoors, but is less accurate (typically within 50–200 meters). And for scripts where speed matters more than precision, use the network provider.
Can Termux:API send SMS without showing a confirmation dialog?
Yes. Unlike making calls (which opens the dialer for confirmation),termux-sms-send sends SMS messages directly without a confirmation dialog, as long as the SMS permission is granted. This makes it very useful for automation scripts. Think of it this way: however, always use this responsibly and only send messages from your own device with your own SIM card.
How do I stop a Termux:API script that's running in a loop?
Press Ctrl+Cin the terminal to interrupt and stop any running script. A quick example: if the script is running in the background or a separate Termux session, use termux-job-scheduler to manage background tasks, or find the process ID with ps aux | grep bash and kill it with kill [PID].
Does Termux:API drain the battery a lot?
It depends on what you're doing. Simple one-time commands like checking battery status or sending a notification use negligible battery. However, continuously running loops that poll the GPS sensor or accelerometer at high frequency will increase battery drain. Always use appropriate sleep intervals in your scripts and only run intensive tasks when necessary.

// 11 — Conclusion: Start Automating Your Android Today

Termux:API is one of the most powerful and underrated tools in the entire Android environment Not what you expected? It turns your phone from a passive device into a programmable. Machine you can automate, monitor, and control entirely from the terminal. From taking photos with a bash script to logging your GPS position, sending SMS. Alerts, reading sensor data, and building voice-driven briefings — the possibilities are genuinely limitless.

In this complete Termux:API guide, you've learned how to install. So and configure the tool correctly, mastered all the major command. Categories including camera, SMS, location, sensors, notifications, and audio, and built several real-world automation scripts you can use right now. Here's how it works: all of this works without root, runs entirely on your Android device, and costs nothing.

The best way to get comfortable with Termux:API is to start experimenting. Take the scripts in this guide, modify them, combine them, and build something new. But break things. Fix them. That's how you actually learn. Check out more tutorials on hydra termux. Blogspot. Com for in-depth guides on Nmap — Metasploit— SSH, Python scripting in Termux, and more. The entire collection is free.

If this guide helped you, share it with a friend who's learning Termux. Drop a comment below with your favorite Termux:API script idea — or let us know if you got stuck somewhere and need help. And the HYDRA TERMUX community is here to help.

Ready to go further? Check out our guide on How to Set Up Cron Jobs in Termux to automatically schedule your Termux:API scripts at specific times and dates — no manual execution needed.

Rixon Xavier

Founder — HYDRA TERMUX

Cybersecurity educator and Termux enthusiast. Creating free tutorials to help Android users learn Linux and ethical cybersecurity since 2023.

⚠️ Disclaimer:This tutorial is for educational purposes only. Always practice on systems you own or have explicit permission to test. HYDRA TERMUX doesn't support illegal activity of any kind.
--- BLOGGER SETTINGS FOR THIS POST: Title: Termux:API Complete Guide — Control Your Android from Terminal (2026) Labels: termux, android, Termux Tutorial, Termux Tools, android tools, terminal, coding, No Root Search Description: Master Termux:API in 2026 — send SMS, take photos, read GPS, control sensors & automate your Android device from terminal. No root required. Custom Robot Tags: all, noodp ---
Previous Post
No Comments Yet
Add Comment
comment url