Welcome back to yet another amazing article. By the way, have you seen the new video uploaded at YT? This article is about about the same. Now, If you think about why do I write this blog after creating a video - well, a video is mostly a quick take (for me). We miss many things. Writing a blog mostly explains everything.

Yes, now you have an idea about what I’m talking about. It’s about Termux-API and how we can make use of them in real life applications.

In that video, I’m specifically talking about termux-camera-photo API.

This is just one from many usable ones. Infact this is the full, or available list of APIs in my knowledge.

termux-am
termux-am-socket
termux-api-start
termux-api-stop
termux-audio-info
termux-backup
termux-battery-status
termux-brightness
termux-call-log
termux-camera-info
termux-camera-photo
termux-change-repo
termux-clipboard-get
termux-clipboard-set
termux-contact-list
termux-dialog
termux-download
termux-dyn-client
termux-fingerprint
termux-fix-shebang
termux-info
termux-infrared-frequencies
termux-infrared-transmit
termux-job-scheduler
termux-keystore
termux-location
termux-media-player
termux-media-scan
termux-microphone-record
termux-nfc
termux-notification
termux-notification-list
termux-notification-remove
termux-open
termux-open-url
termux-reload-settings
termux-reset
termux-restore
termux-sensor
termux-setup-package-manager
termux-setup-storage
termux-share
termux-sms-inbox
termux-sms-list
termux-sms-send
termux-speech-to-text
termux-storage-get
termux-telephony-call
termux-telephony-cellinfo
termux-telephony-deviceinfo
termux-toast
termux-torch
termux-tts-engines
termux-tts-speak
termux-usb
termux-vibrate
termux-volume
termux-wake-lock
termux-wake-unlock
termux-wallpaper
termux-wifi-connectioninfo
termux-wifi-enable
termux-wifi-scaninfo

Unfortunately, most are not listed in API docs or no where. But what’s cute about these APIs are that, they are made for everyone to use. You don’t need need to know any internals of any of these. Termux gives a high-level API to interact with our hardware and Android API.

If you take a look at the camera API help, it says: [-c camera-id] output-file where camera-id can be seen from termux-camera-info.

There is another interesting API which is termux-sms-[list,send,inbox] . When you list the inbox, you will get the output in JSON.

[
  {
    "threadid": 95,
    "type": "inbox",
    "read": true,
    "sender": "Amal",
    "number": "+91894xxxxx",
    "received": "2022-06-18 19:17:38",
    "body": "bruv! take scooter",
    "_id": 2453
  }
 ]

By default it will output the freequent messages. You can also limit the output with the -limit flag.

Now, how to utilise this API depends on you. But I could impress you to use it by saying - listen for incoming messages or set a corn job, on receiving check for a specific mobile number, check if the content hash matches with the one that you’re looking for, if yes, nuke everything!

Or , what about building an online services or an application on your own which keeps in sync with your inbox. So you could read your message without your phone in hand. Well, that’s just an alternative to Google’s stock Message app.

  • termux-open-url Is yet another useful API. Again, the awesomeness depends on how you use it. But, I’ve a video explaining the same.

An important API that you should be playing is the notification API. You could do a corn job or whatever event, to let you notify you about it, you should use the notification. Termux can make use of the Android ’s notification API so do our script. You can even notify using a custom notification sound. Which can be changed from app/notification settings. Make your notification sound different from normal notification sound of your phone. So you’ll know if your server has went down or crypto is falling and you’re going bankrupt in few minutes.

  • termux-job-scheduler : Alternative to a cron job but you’re very limited about the interval of script execution. Basically, you are running some kind of script at the interval of 15 minutes. You cannot go less than that.

Note that since Android N, the minimum period is 900,000ms (15 minutes).

You should first start the API service by termux-api-start and stop whenever needed. You can test your API with below script:

#!/data/data/com.termux/files/usr/bin/python
import random
name=str(random.randint(1,20))
path="/data/data/com.termux/files/home/job"
with open(f"{path}/{name}.txt",'w') as f:
        f.write(name)

termux-job-scheduler -s ~/scripts/RandScript --period-ms 900000 Check if the files are created in the folder that is mentioned in in path. If yes, you’re good to go. See the available pending jobs with termux-job-scheduler -p.

Other APIs are self explanatory and you can access the help page of any of these by appending -h flag after the name of API. Ofcourse, I’m not going to cover everything. But, I’ll append whatever new stuff that I’ve done here.

I would say, the APIs will get intersting depends on our need. These APIs are just doors you can open and take whatever you need. That’s all, as always, I’m just letting you know the possibilities. You as a programmer can tweak it in any ways.

That’s all. Do let me know your suggestions & feedbacks via e-mail.

It’s Friday again. Have a better weekend.đź‘“