I've been experimenting with Termux, the Android terminal emulator.
It is an excellent application that allows access to the Android operating system without requiring root access.
What I would like to be able to achieve is execute scripts/commands within Termux from within another Android application installed on the same device.
I believe Termux used to allow Tasker tasks to be executed via intents, however this doesnt appear to be the case now.
Is it possible to execute a script of set of commands via Termux (or any other such app) from another Android application.
or...
Is it possible to access the underlying Android operation system and execute scripts from within an Android app?
UPDATE
When I execute this code from my Android application
try {
ProcessBuilder pb = new ProcessBuilder("pkg", "install -y", "ffmpeg python");
final Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
Log.d(TAG, "onCreate(2): " + line);
}
} catch (Exception ex) {
Log.e(TAG, "onCreate: ", ex);
}
I get this error message
java.io.IOException: Cannot run program "pkg": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at org.home.assignment.shell.MainActivity.commandThree(MainActivity.java:32)
at org.home.assignment.shell.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3243)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3407)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7343)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:141)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at org.home.assignment.shell.MainActivity.commandThree(MainActivity.java:32)
at org.home.assignment.shell.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3243)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3407)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7343)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
However com.termux can execute commands like this. How do I get permission to execute these commands in my applicatgion?
String[] cmdArray = {"sh", "-c", cmd}; Process p = Runtime.getRuntime().exec(cmdArray);worked for me on an unrooted low-end phone, but may not work on unrooted new phones.