What Is Termux-API ? Termux-API Commands

    - Advertisement -


    Termux-API is an add-on for the Termux application. With the help of Termux-API, you can do so many things without leaving your terminal, like clicking pictures, recording audio, changing your brightness level, accessing call logs, contacts, messages, and many more.

    Installing Termux-API

    • Download and install Termux-API from F-Droid or PlayStore (I recommend you to download it from F-Droid, but if you have installed Termux from PlayStore, then you should install all termux addons from only PlayStore, or you can uninstall Termux and re-install it from F-Droid)
    • After successful installation of Termux-API, open Termux and type the following command.
    pkg install termux-api
    • This will install the termux-API package. After successful installation, you are ready to use termux-API, but before that, don’t forget to give all permissions to Termux-API from your device settings. Like allowing to access the camera, microphone and also modifying system settings. (You can watch my YouTube video if you got stuck somewhere during the installation process.)

    Termux-API Commands List

    Below are the list of commands that are currently available for Termux-API

    Check Your Battery Status

    You can check your battery status without leaving your terminal by following command

    result of termux-battery-status command

    As you can see in the above image, termux-battery-status will show you the details of your device battery like its health, percentage, and many more.

    Set your screen brightness level

    With the help of the termux-brightness command, you can change your screen brightness level between 0 and 255 or auto from the terminal.

    For example : If you want to change your brightness level to 100 type

    termux-brightness 100
    - Advertisement -

    And this will change your brightness level to 100.

    result of termux-brightness 100 command
    termux-brightness 100
    List SMS messages
    result of termux-sms-list command

    There are some additional options mentioned below that you can use with this command.

    -d         show dates when messages were created
    -l limit   offset in sms list (default: 10)
    -n         show phone numbers
    -o offset  offset in sms list (default: 0)
    -t type    the type of messages to list (default: inbox):
    Send SMS messages
    termux-sms-send -n number [text]

    You can add a text file to send as an argument, but it gets read from standard input if no arguments are given. You can also add more numbers by separating numbers by comma.

    -n number(s)  recipient number(s) - separate multiple numbers by commas
    Call someone directly from termux
    termux-telephony-call [number]

    Phone number should be written in appropriate format.

    Get information about SIM cards of your device
    - Advertisement -

    This command will show information about SIM cards that are available in your device.

    Get information about telephony device

    Output is returned in JSON format, and it will show details like if your data is enabled or not, network operator, phone type, and many more.

    Print phone call history

    If you want to see your call logs within your terminal, you can do it by termux-call-log command. The result will be displayed in JSON format, and it will display details like name, phone number, call type, date, and duration.

    result of termux-call-log command
    Download any file from web
    termux-download [-d description] [-t title] [-p path] url-to-download

    To download any file from the web, you’ll require the URL of that file, the path where you want to save the downloaded file, and the title and description with the termux-download command. The downloading progress will be displayed in the notification.

    List all contacts

    termux-contact-list lists all the contacts saved in your device in json format. It includes phone number and name.

    result of termux-contact-list command
    Get information about device camera/cameras
    - Advertisement -

    This command will show you information about your device cameras in JSON format. It will show details like id, facing, and jpeg output sizes. Mostly for the back-facing camera, id is 0, and for the front-facing camera, id is 1.

    result of termux-camera-info command
    Take photo from camera
    termux-camera-photo [-c camera-id] output-file

    With the help of the above command, you can take photos from your camera. You have to specify the camera id and the output file. As I mentioned earlier camera id for the back camera is 0 and for the front camera is 1. So, for example, if I have to take a photo from the front camera, I’ll write

    termux-camera-photo -c 1 example.jpeg

    After I hit enter, this will take a photo from my front camera and save it to my current working directory, as example.jpeg.

    result of termux-camera-photo command
    Get the device location

    You’ll get information like latitude, longitude, altitude and many more as shown in image below.


    You can use two different options with this command to change provider and the type of request.

    -p provider  location provider [gps/network/passive] (default: gps)
    -r request   kind of request to make [once/last/updates] (default: once)
    Schedule a script to run later or periodically

    You can use various options with this command that are given below.

    Usage: termux-job-scheduler [options]
    Schedule a script to run at specified intervals.
      -p/--pending               list pending jobs and exit
      --cancel-all               cancel all pending jobs and exit
      --cancel                   cancel given job-id and exit
    Options for scheduling:
      -s/--script path           path to the script to be called
      --job-id int               job id (will overwrite any previous job with the same id)
      --period-ms int            schedule job approximately every period-ms milliseconds (default 0 means once).
                                 Note that since Android N, the minimum period is 900,000ms (15 minutes).
      --network text             run only when this type of network available (default any): any|unmetered|cellular|not_roaming|none
      --battery-not-low boolean  run only when battery is not low, default true (at least Android O)
      --storage-not-low boolean  run only when storage is not low, default false (at least Android O)
      --charging boolean         run only when charging, default false
      --persisted boolean        should the job survive reboots, default false
      --trigger-content-uri text (at least Android N)
      --trigger-content-flag int default 1, (at least Android N)
    Get or set the system clipboard text

    termux-clipboard-get command will give you output of the saved text in your system clipboard.

    result of termux-clipboard-get command
    termux-clipboard-set [text]

    With the help of termux-clipboard-set, one can directly set any text in system’s clipboard. Text is either read from standard input or from command line arguments.

    result of the termux-clipboard-set command
    Use fingerprint sensor on device to check for authentication

    You can also use your device’s fingerprint sensor to check for authentication. Again the output is returned in json format as shown below.

    Query infrared transmitter’s supported carrier frequencies

    Output is returned in JSON format, and this API command can only be used on devices with an infrared transmitter (IR Blaster).

    Transmit an infrared pattern
    termux-infrared-transmit -f frequency pattern

    You have to specify the patterns in comma-separated on/off intervals, like as ‘10,30,10,50’, and only patterns that are shorter than 2 seconds will be transmitted. So you can use termux as a remote for your television if your device has an IR Blaster. No need to install an additional app for that, and the frequency in hertz is mandatory.

    Show dialog widget of your input
    termux-dialog [options]

    You can see the dialog of your input by using the termux-dialog command and adding the available options for this command. The output is returned in JSON format.

    For example if I have to see a confirmation dialog for that I can type

    termux-dialog confirm

    And this will show me a confirmation dialog.

    termux-dialog confirm

    There are many more options that you can use with termux-dialog command, they are listed below.

    -l, list   List all widgets and their options
    -t, title  Set title of input dialog (optional)
    WIdget-specific options
    confirm - Show confirmation dialog
        [-i hint] text hint (optional)
        [-t title] set title of dialog (optional)
    checkbox - Select multiple values using checkboxes
        [-v ",,,"] comma delim values to use (required)
        [-t title] set title of dialog (optional)
    counter - Pick a number in specified range
        [-r min,max,start] comma delim of (3) numbers to use (optional)
        [-t title] set title of dialog (optional)
    date - Pick a date
        [-t title] set title of dialog (optional)
        [-d "dd-MM-yyyy k:m:s"] SimpleDateFormat Pattern for date widget output (optional)
    radio - Pick a single value from radio buttons
        [-v ",,,"] comma delim values to use (required)
        [-t title] set title of dialog (optional)
    sheet - Pick a value from sliding bottom sheet
        [-v ",,,"] comma delim values to use (required)
        [-t title] set title of dialog (optional)
    spinner - Pick a single value from a dropdown spinner
        [-v ",,,"] comma delim values to use (required)
        [-t title] set title of dialog (optional)
    speech - Obtain speech using device microphone
        [-i hint] text hint (optional)
        [-t title] set title of dialog (optional)
    text - Input text (default if no widget specified)
        [-i hint] text hint (optional)
        [-m] multiple lines instead of single (optional)*
        [-n] enter input as numbers (optional)*
        [-p] enter input as password (optional)
        [-t title] set title of dialog (optional)
           * cannot use [-m] with [-n]
    time - Pick a time value
        [-t title] set title of dialog (optional)
    Scan media files in termux

    Scan media file and add to the media content provider.

    termux-media-scan [-v] [-r] file [file...]
    -r  scan directories recursively
    -v  verbose mode
    Play specified media file using termux media player
    termux-media-player [command] [args]
    info        Displays current playback information
    play        Resumes playback if paused
    play <file> Plays specified media file
    pause       Pauses playback
    stop        Quits playback
    Record any audio from your device microphone
    termux-microphone-record [args]

    The recorded file is saved in your internal storage named as TermxAudioRecording by default, below are the options that you can use with termux-microphone-record command.

    -d           Start recording w/ defaults
    -f <file>    Start recording to specific file
    -l <limit>   Start recording w/ specified limit (in seconds, unlimited for 0)
    -e <encoder> Start recording w/ specified encoder (aac, amr_wb, amr_nb)
    -b <bitrate> Start recording w/ specified bitrate (in kbps)
    -r <rate>    Start recording w/ specified sampling rate (in Hz)
    -c <count>   Start recording w/ specified channel count (1, 2, ...)
    -i           Get info about current recording
    -q           Quits recording
    Display a system notification
    termux-notification [options]
     --action action          action to execute when pressing the notification
     --alert-once             do not alert when the notification is edited
     --button1 text           text to show on the first notification button
     --button1-action action  action to execute on the first notification button
     --button2 text           text to show on the second notification button
     --button2-action action  action to execute on the second notification button
     --button3 text           text to show on the third notification button
     --button3-action action  action to execute on the third notification button
     -c/--content content     content to show in the notification. Will take precedence over stdin.
     --group group            notification group (notifications with the same group are shown together)
     -h/--help                show this help
     --help-actions           show the help for actions
     -i/--id id               notification id (will overwrite any previous notification with the same id)
     --image-path path        absolute path to an image which will be shown in the notification
     --led-color rrggbb       color of the blinking led as RRGGBB (default: none)
     --led-off milliseconds   number of milliseconds for the LED to be off while it's flashing (default: 800)
     --led-on milliseconds    number of milliseconds for the LED to be on while it's flashing (default: 800)
     --on-delete action       action to execute when the the notification is cleared
     --ongoing                pin the notification
     --priority prio          notification priority (high/low/max/min/default)
     --sound                  play a sound with the notification
     -t/--title title         notification title to show
     --vibrate pattern        vibrate pattern, comma separated as in 500,1000,200
     --type type              notification style to use (default/media)
    Media actions (available with –type “media”)
     --media-next             action to execute on the media-next button
     --media-pause            action to execute on the media-pause button
     --media-play             action to execute on the media-play button
     --media-previous         action to execute on the media-previous button
    Remove a notification previously shown with termux-notification –id
    termux-notification-remove [id]

    id is value that was used previously to show notification with termux-notification command.

    Get information about sensors available in device
    termux-sensor [options]

    With the above command, you can get information about the sensors available in your device and live data. Below are some options that you can use with this command.

    -h, help           Show this help
    -a, all            Listen to all sensors (WARNING! may have battery impact)
    -c, cleanup        Perform cleanup (release sensor resources)
    -l, list           Show list of available sensors
    -s, sensors [,,,]  Sensors to listen to (can contain just partial name)
    -d, delay [ms]     Delay time in milliseconds before receiving new sensor update
    -n, limit [num]    Number of times to read sensor(s) (default: continuous) (min: 1)
    Share a file
    termux-share [options] [file]

    Share a specified or text from standard input with this command and if file to share is not specified, program wil read standard input.

    -a action        which action to performed on the shared content:
                     edit/send/view (default:view)
    -c content-type  content-type to use (default: guessed from file extension,
                     text/plain for stdin)
    -d               share to the default receiver if one is selected
                     instead of showing a chooser
    -t title         title to use for shared content (default: shared file name)
    Request a file from system and write it to the specified file
    termux-storage-get [output-file]

    Make sure that the specified path is writable, and the output file is mandatory argument.

    Show a transient popup in notification
    termux-toast [options] [text]

    You can supply text to show as an argument or it gets read from standard input if no arguments are given.

    -h  show this help
    -b  set background color (default: gray)
    -c  set text color (default: white)
    -g  set position of toast: [top, middle, or bottom] (default: middle)
    -s  only show the toast for a short while

    Color can be a standard value like red or it can be 6/8 digit hex value.

    Turn torch on or off
    termux-torch [on | off]

    You can only specify only one value at a time on or off.

    Get information about installed TTS engines
    Speak text with TTS engines

    You can supply text as an argument or it can be read from standard input if no argument is supplied. Options that you can use with this command are listed below

    -e engine    TTS engine to use (see termux-tts-engines)
     -l language  language to speak in (may be unsupported by the engine)
     -n region    region of language to speak in
     -v variant   variant of the language to speak in
     -p pitch     pitch to use in speech. 1.0 is the normal pitch,
                    lower values lower the tone of the synthesized voice,
                    greater values increase it.
     -r rate      speech rate to use. 1.0 is the normal speech rate,
                    lower values slow down the speech
                    (0.5 is half the normal speech rate)
                    while greater values accelerates it
                    (2.0 is twice the normal speech rate).
     -s stream    audio stream to use (default:NOTIFICATION), one of:
    List or access available USB devices
    -l               list available devices
    -r               show permission request dialog if not already granted
    -e command       execute the specified command with a file descriptor
                     referring to the device as its argument
    Vibrate the device
    termux-vibrate [options]
    -d duration  the duration to vibrate in ms (default:1000)
    -f           force vibration even in silent mode
    Change Volume
    termux-volume [stream] [volume]

    Valid streams are alarm, music, notification, ring, system and call.

    Change wallpaper Of Your device
    termux-wallpaper cmd [options]
    -f <file>  set wallpaper from file
    -u <url>   set wallpaper from url resource
    -l         set wallpaper for lockscreen (Nougat and later)
    Get information about WiFi connection

    This will show information like Access Point,Mac address, device IP and many more.

    On / Off WiFi
    termux-wifi-enable [true | false]

    You can only use one value at a time true or false , true value enables WiFi and the false value disables it.

    Get information about the last WiFi scan

    These were the Termux API commands that you can use in termux. I hope it helps you 🙂

    - Advertisement -

    Recent Articles