mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Receive "RUN_COMMAND_ARGUMENTS" extra for "RUN_COMMAND_ACTION" intent
as a string array extra instead of a string extra since TermuxService expects it that way. Added "RUN_COMMAND_BACKGROUND" boolean extra so that Termux session can be started in background when running a command. Updated usage docs. Check #1029 for details.
This commit is contained in:
committed by
Leonid Pliushch
parent
51370799c7
commit
9e7029b76a
@@ -15,18 +15,32 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* When allow-external-apps property is set to "true", Termux is able to process execute intents
|
||||
* sent by third-party applications.
|
||||
* When allow-external-apps property is set to "true" in ~/.termux/termux.properties, Termux
|
||||
* is able to process execute intents sent by third-party applications.
|
||||
*
|
||||
* Third-party program must declare com.termux.permission.RUN_COMMAND permission and it should be
|
||||
* granted by user.
|
||||
* Full path of command or script must be given in "RUN_COMMAND_PATH" extra.
|
||||
* The "RUN_COMMAND_ARGUMENTS", "RUN_COMMAND_WORKDIR" and "RUN_COMMAND_BACKGROUND" extras are
|
||||
* optional. The background mode defaults to false.
|
||||
*
|
||||
* Sample code to run command "top":
|
||||
* Sample code to run command "top" with java:
|
||||
* Intent intent = new Intent();
|
||||
* 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);
|
||||
* startService(intent);
|
||||
*
|
||||
* Sample code to run command "top" with "am startservice" command:
|
||||
* am startservice --user 0 -n com.termux/com.termux.app.RunCommandService
|
||||
* -a com.termux.RUN_COMMAND
|
||||
* --es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/top'
|
||||
* --esa com.termux.RUN_COMMAND_ARGUMENTS '-n,5'
|
||||
* --es com.termux.RUN_COMMAND_WORKDIR '/data/data/com.termux/files/home'
|
||||
* --ez com.termux.RUN_COMMAND_BACKGROUND 'false'
|
||||
*/
|
||||
public class RunCommandService extends Service {
|
||||
|
||||
@@ -34,6 +48,7 @@ public class RunCommandService extends Service {
|
||||
public static final String RUN_COMMAND_PATH = "com.termux.RUN_COMMAND_PATH";
|
||||
public static final String RUN_COMMAND_ARGUMENTS = "com.termux.RUN_COMMAND_ARGUMENTS";
|
||||
public static final String RUN_COMMAND_WORKDIR = "com.termux.RUN_COMMAND_WORKDIR";
|
||||
public static final String RUN_COMMAND_BACKGROUND = "com.termux.RUN_COMMAND_BACKGROUND";
|
||||
|
||||
class LocalBinder extends Binder {
|
||||
public final RunCommandService service = RunCommandService.this;
|
||||
@@ -52,8 +67,9 @@ public class RunCommandService extends Service {
|
||||
|
||||
Intent execIntent = new Intent(TermuxService.ACTION_EXECUTE, programUri);
|
||||
execIntent.setClass(this, TermuxService.class);
|
||||
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringExtra(RUN_COMMAND_ARGUMENTS));
|
||||
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringArrayExtra(RUN_COMMAND_ARGUMENTS));
|
||||
execIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, intent.getStringExtra(RUN_COMMAND_WORKDIR));
|
||||
execIntent.putExtra(TermuxService.EXTRA_EXECUTE_IN_BACKGROUND, intent.getBooleanExtra(RUN_COMMAND_BACKGROUND, false));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
this.startForegroundService(execIntent);
|
||||
|
Reference in New Issue
Block a user