Termux API Skill 📱
Control your Android device through Termux API commands. This skill allows you to interact with Android hardware and system features programmatically.
Prerequisites
Required:
- •Termux API app installed from F-Droid (not Google Play)
- •Termux API package:
pkg install termux-api - •Grant necessary Android permissions when prompted
Installation:
pkg install termux-api
Note: Some commands require Android permissions. Grant them when prompted or via Settings → Apps → Termux:API → Permissions.
🔋 Battery & Power
Get Battery Status
termux-battery-status
Returns JSON with battery percentage, temperature, status (charging/discharging), plugged state, etc.
Example:
# Check if battery is low termux-battery-status | jq '.percentage'
📸 Camera
Take Photo
termux-camera-photo -c <camera-id> <output-file>
Parameters:
- •
-c <id>: Camera ID (0=back, 1=front) - •Output file path
Examples:
# Take photo with back camera termux-camera-photo -c 0 ~/photo.jpg # Take selfie with front camera termux-camera-photo -c 1 ~/selfie.jpg
List Available Cameras
termux-camera-info
📋 Clipboard
Get Clipboard Content
termux-clipboard-get
Set Clipboard Content
termux-clipboard-set "text to copy"
Examples:
# Copy file contents to clipboard cat notes.txt | termux-clipboard-set # Paste clipboard to file termux-clipboard-get > clipboard.txt
📞 Contacts
List All Contacts
termux-contact-list
Returns JSON array of contacts with names, numbers, emails.
Example:
# Find contact by name
termux-contact-list | jq '.[] | select(.name | contains("John"))'
# Count total contacts
termux-contact-list | jq '. | length'
💬 Dialog & User Input
Show Dialog
# Text input dialog termux-dialog text -t "Enter your name" # Confirm dialog termux-dialog confirm -t "Are you sure?" # Date picker termux-dialog date -t "Select date" # Time picker termux-dialog time -t "Select time" # Radio buttons termux-dialog radio -t "Choose one" -v "Option 1,Option 2,Option 3" # Checkbox termux-dialog checkbox -t "Select items" -v "Item 1,Item 2,Item 3" # Spinner/dropdown termux-dialog spinner -t "Select" -v "Choice 1,Choice 2,Choice 3"
Example:
# Get user input name=$(termux-dialog text -t "Enter name" | jq -r '.text') echo "Hello, $name!"
📍 Location (GPS)
Get Current Location
termux-location -p <provider> -r <request>
Providers:
- •
gps: GPS hardware (more accurate, slower, outdoor) - •
network: Network/WiFi (faster, less accurate) - •
passive: Use cached location
Request types:
- •
once: Get location once (default) - •
last: Get last known location - •
updates: Continuous updates
Examples:
# Get GPS location termux-location -p gps -r once # Quick network location termux-location -p network -r last # Parse coordinates termux-location -p network -r once | jq -r '.latitude, .longitude'
🔊 Media & Audio
Media Player
# Play audio file termux-media-player play <file> # Pause playback termux-media-player pause # Info about current track termux-media-player info
Text-to-Speech
termux-tts-speak "Hello from Pepebot" # Different language termux-tts-speak -l en-US "Hello" # Different speech rate and pitch termux-tts-speak -r 0.5 -p 2.0 "Slow and high pitch"
Parameters:
- •
-l: Language (en-US, id-ID, etc.) - •
-r: Speech rate (0.1-2.0) - •
-p: Pitch (0.1-2.0) - •
-e: Engine name - •
-s: Stream type
Speech-to-Text
termux-speech-to-text
Records audio and converts to text (requires microphone permission).
🔔 Notifications
Display Notification
termux-notification -t "Title" -c "Content"
Parameters:
- •
-t: Title - •
-c: Content/message - •
-i: ID (for updating/removing) - •
--priority: min/low/default/high/max - •
--sound: Play notification sound - •
--vibrate: Vibrate pattern (e.g., "200,100,200") - •
--action: Add action button - •
--on-delete: Command to run on dismiss
Examples:
# Simple notification termux-notification -t "Pepebot" -c "Task completed!" # Notification with sound and vibration termux-notification -t "Alert" -c "Important!" --sound --vibrate "500,200,500" # Persistent notification termux-notification -i 123 -t "Bot Running" -c "Click to stop" --ongoing # Remove notification termux-notification-remove 123
💾 Storage
Get Storage Info
termux-storage-get
Request access to external storage (shows permission dialog).
After granting permission, access shared storage at:
- •
~/storage/shared/- Internal storage - •
~/storage/external-1/- SD card (if available) - •
~/storage/downloads/- Downloads folder - •
~/storage/dcim/- Camera photos - •
~/storage/pictures/- Pictures folder
📱 Device Info
WiFi Connection Info
termux-wifi-connectioninfo
Returns SSID, IP address, link speed, frequency, etc.
Example:
# Get current WiFi name termux-wifi-connectioninfo | jq -r '.ssid' # Check signal strength termux-wifi-connectioninfo | jq '.rssi'
WiFi Scan
termux-wifi-scaninfo
Scan for available WiFi networks.
Sensor Info
termux-sensor -l
List available sensors (accelerometer, gyroscope, light, proximity, etc.)
Read Sensor Data
termux-sensor -s <sensor-name> -n <count>
Example:
# Read accelerometer termux-sensor -s "BMI160 accelerometer" -n 1 # Monitor light sensor termux-sensor -s "Light Sensor" -n 10
📞 Telephony
Send SMS
termux-sms-send -n <number> "message"
Example:
termux-sms-send -n "+1234567890" "Hello from Pepebot!"
⚠️ Note: Requires SMS permission. May not work on all devices/carriers.
Get SMS List
termux-sms-list -l <limit>
Parameters:
- •
-l: Limit number of messages - •
-n: Phone number filter - •
-t: Type (all/inbox/sent/draft) - •
-d: Show date
Make Phone Call
termux-telephony-call <number>
Get Device Info
termux-telephony-deviceinfo
Returns device ID, software version, phone type, etc.
📲 System
Brightness Control
# Set brightness (0-255) termux-brightness 128 # Get current brightness termux-brightness
Volume Control
# Set volume termux-volume <stream> <level> # Streams: alarm, music, notification, ring, system, call termux-volume music 10
Vibrate
# Vibrate for duration (milliseconds) termux-vibrate -d 1000 # Vibrate pattern termux-vibrate -f 500,200,500,200
Toast Message
termux-toast "Hello from Pepebot" # Short or long duration termux-toast -s "Short toast" termux-toast -l "Long toast" # Different position termux-toast -g top "Top toast" termux-toast -g middle "Middle toast" termux-toast -g bottom "Bottom toast"
Share Content
# Share file termux-share <file> # Share text echo "Hello" | termux-share # Choose specific app termux-share -a org.telegram.messenger <file>
Open URL
termux-open-url <url>
Example:
termux-open-url "https://google.com" termux-open-url "tel:+1234567890" termux-open-url "mailto:user@example.com"
🎯 Common Use Cases
1. Battery Monitor
# Alert when battery is low
battery=$(termux-battery-status | jq '.percentage')
if [ $battery -lt 20 ]; then
termux-notification -t "Low Battery" -c "Only $battery% remaining"
fi
2. Location Logger
# Log current location location=$(termux-location -p network -r once) echo "$(date): $location" >> location_log.txt
3. Smart Notifications
# Notify when someone mentions you
termux-notification \
-t "New Message" \
-c "John mentioned you" \
--sound \
--vibrate "200,100,200" \
--action "termux-open-url 'telegram://'"
4. Voice Assistant
# Voice command input text=$(termux-speech-to-text) termux-tts-speak "You said: $text"
5. Auto Photo
# Take photo every hour
while true; do
termux-camera-photo -c 0 ~/photos/$(date +%Y%m%d_%H%M%S).jpg
sleep 3600
done
6. Clipboard Sync
# Sync clipboard to file termux-clipboard-get > ~/.clipboard_backup
7. WiFi Monitor
# Check WiFi connection
ssid=$(termux-wifi-connectioninfo | jq -r '.ssid')
if [ "$ssid" = "MyHomeWiFi" ]; then
echo "At home"
else
echo "Away from home"
fi
🔐 Permissions
Required Android permissions (grant when prompted):
- •Camera:
termux-camera-* - •Location:
termux-location - •Microphone:
termux-speech-to-text - •Contacts:
termux-contact-list - •SMS:
termux-sms-* - •Phone:
termux-telephony-* - •Storage:
termux-storage-get - •Sensors:
termux-sensor
Grant permissions: Settings → Apps → Termux:API → Permissions → Enable required permissions
💡 Tips
- •Check Command Availability: Run
which <command>to verify installation - •JSON Parsing: Use
jqfor parsing JSON output - •Error Handling: Check exit codes with
$? - •Permissions: Grant all permissions at once in Android settings
- •Background Tasks: Use
tmuxto keep scripts running - •Logging: Pipe output to files for debugging
🐛 Troubleshooting
Command not found:
pkg install termux-api
Permission denied:
- •Go to Android Settings → Apps → Termux:API
- •Enable required permissions
- •Try command again
Camera not working:
- •Close all apps using camera
- •Grant camera permission
- •Try different camera ID
Location not available:
- •Enable Location in Android settings
- •Grant location permission to Termux:API
- •Try different provider (gps/network)
🔗 References
Note: This skill is only available when running Pepebot on Android via Termux. Commands will fail on other platforms.