The powerful functions of Android terminal emulator Termux: application calls Termux to execute commands

The powerful functions of Android terminal emulator Termux: application calls Termux to execute commands

Introduction to Termux

Termux is an open source Android terminal emulator that uses apt and dpkg as package management tools to easily install, upgrade and manage various software packages.

Termux provides support for multiple programming languages, including Python, Ruby, Node.js, PHP, Perl, etc. After simple configuration, you can write and run code on your Android device. It also provides a wealth of command line tools, such as grep, awk, sed, and various text processing and network diagnostic tools.

Termux allows users to access and manage files on Android devices, including internal and external storage. It also includes an SSH client and server, allowing users to remotely connect to other computers or have other computers connect to Termux. In addition, it also supports version control systems such as Git and Subversion, and users can perform version control operations on their devices.

Call Termux to execute commands

Since Termux version 0.95, third-party applications can run commands in the context of a Termux application by sending an intent to RunCommandService or becoming a plugin for the termux-tasker plugin client.

  1. Configure Termux to allow external applications to call: Open Termux, modify the ~/.termux/termux.properties file, and add a line:
 allow-external-apps = true

For Android versions >= 10.0, you need to enable associated application permissions for Termux, otherwise third-party applications will not be allowed to directly start Termux in the background, but can only be called when Termux is running in the background.

Enable the "Associated Apps" permission: [App information] -> [Apps] -> [Termux] -> [Permissions] -> [Associated Apps].

  1. Application configuration: Request com.termux.permission.RUN_COMMAND permission in the AndroidManifest.xml file and send an Intent to RunCommandService in the code.
 <uses-permission android:name="com.termux.permission.RUN_COMMAND"/>

Intent construction in the code:

 intent.setClassName("com.termux", "com.termux.app.RunCommandService"); intent.setAction("com.termux.RUN_COMMAND"); intent.putExtra("com.termux.RUN_COMMAND_PATH", "/data/data/com.termux/files/usr/bin/top"); intent.putExtra("com.termux.RUN_COMMAND_ARGUMENTS", new String[]{"-n", "5"}); intent.putExtra("com.termux.RUN_COMMAND_WORKDIR", "/data/data/com.termux/files/home"); intent.putExtra("com.termux.RUN_COMMAND_BACKGROUND", false); intent.putExtra("com.termux.RUN_COMMAND_SESSION_ACTION", "0"); startService(intent);

Related parameter description:

  • com.termux.RUN_COMMAND_PATH: the ELF file called;
  • com.termux.RUN_COMMAND_ARGUMENTS: call command parameters;
  • com.termux.RUN_COMMAND_WORKDIR: working directory;
  • com.termux.RUN_COMAND_BACKGROUND: Whether to run in the background. If true, TermuxActivity will not be entered;
  • com.termux.RUN_COMMAND_SESSION_ACTION: Session action.

The top command is called here: /data/data/com.termux/files/usr/bin/top

<<:  Key APIs and techniques for adjusting Android brightness to achieve personalized APP brightness settings

>>:  Exploration and practice of Ctrip Hotel's unified cloud mobile phone platform

Recommend

Android M Developer Preview 2 Vulnerability Exposed

[[139908]] Google released Android M Developer Pr...

@Barber: Why is it so difficult to dye your hair the color you want? !

Do you have such troubles about hair dyeing? I ha...

Are you still missing an ecosystem to become a “great” Internet company?

Is it reliable for startups to build their own ec...

Taking a census of galaxies? China's sky survey helps resolve the Hubble crisis!

The English version of Science China Physics, Mec...

Lao Luo has so many fans, why is his business not very successful?

Not long ago, I read the remarks of Wu Shichun, p...

How to effectively use the AARRR model to acquire and convert customers?

Taking two activities as examples, this article s...

2018 Tik Tok Research Report! (Full version)

“5 minutes on TikTok is like 1 hour in the real w...

How to build your first machine learning model on your iPhone

introduction As a data scientist, I have always h...