Termux:API Complete Guide — Control Your Android from Terminal (2026)
Termux:API Complete Guide — Control Your Android from Terminal (2026)
- Introduction — what's Termux:API?
- Installation — Termux:API App + Package Setup
- Camera, Torch & Media Controls
- SMS, Calls & Contact Management
- Sensors, Location & Device Info
- Automation Scripts — Real-World Use Cases
- Common Errors and Fixes
- Pro Tips for Power Users
- Command Reference Table
- Frequently Asked Questions
- Conclusion
// 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.
// 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.
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.
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).
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:
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:
termux-battery-status If everything is installed correctly, you should see JSON output like this:
{ "health": "GOOD", "percentage": 87, "plugged": "UNPLUGGED", "status": "DISCHARGING", "temperature": 32. 0
} 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.
# 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 1 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:
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:
# 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:
# 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:
# 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 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.
Sending an SMS Message
# 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:
# 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.
# Pretty-print SMS list using jq
termux-sms-list -l 5 | jq '. [] | {from:. Number, msg:. Body}' Call Log and Contact List
# 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
# 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:
# 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:
# 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:
{ "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:
# 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
# Detailed battery status
termux-battery-status # Extract just the percentage using jq
termux-battery-status | jq '. Percentage' Device and Network Info
# 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:
# 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" 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:
#! /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%:
#! /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:
#! /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:
#! /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" 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..
# 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
termux-vibrate -d 500vibrates the phone for 500ms.. Useful in scripts where you want a tactile notification without sound.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-status | Device | Returns battery level, health, temp, status | No |
| termux-camera-photo | Camera | Captures a photo with front or rear camera | No |
| termux-camera-info | Camera | Lists available cameras and resolutions | No |
| termux-clipboard-get | Clipboard | Reads Android clipboard content | No |
| termux-clipboard-set | Clipboard | Writes text to Android clipboard | No |
| termux-contact-list | Contacts | Lists all contacts in JSON format | No |
| termux-call-log | Calls | Shows recent call history | No |
| termux-location | GPS | Returns GPS or network-based coordinates | No |
| termux-notification | Notifications | Sends a custom Android notification | No |
| termux-sensor | Sensors | Reads accelerometer, gyro, light, etc. | No |
| termux-sms-list | SMS | Lists SMS inbox/sent messages | No |
| termux-sms-send | SMS | Sends an SMS to a phone number | No |
| termux-telephony-call | Calls | Opens dialer to call a number | No |
| termux-torch | Hardware | Toggles flashlight on/off | No |
| termux-tts-speak | Audio | Speaks text aloud using Android TTS | No |
| termux-media-player | Audio | Play, pause, stop, info for audio files | No |
| termux-vibrate | Hardware | Vibrates the device for a set duration | No |
| termux-wifi-connection-info | Network | Shows current WiFi SSID, IP, signal info | No |
| termux-wifi-scan-info | Network | Scans and lists nearby WiFi networks | No |
| termux-telephony-device-info | Network | Returns device ID and network operator info | No |
// 10 — Frequently Asked Questions
pkg install termux-api inside Termux AND that permissions are granted in Android settings.-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.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.termux-job-scheduler to manage background tasks, or find the process ID with ps aux | grep bash and kill it with kill [PID].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.
