I want to thank you for taking the time to work on this. I know it’s a labor of love, but you don’t have to. Let me try to analyze it step-by-step. The first thing you mention is the `allow-external-apps` property. The documentation is very lacking and disjointed (I’m working on it!) there are two ways to set this setting up, you can run `termux-setup-storage` from the termux shell and it will automatically create a virtual storage space and shared space in addition to the `termux.properties` file. This file should be located in a hidden folder at..
`~/.termux/termux.properties`
I believe nano is natively installed with termux. (pkg install nano) you can then `nano ~/.termux/termux.properties` and it believe it is the first commented setting (`allow-external-apps=true`) you’d want to un-comment. The documentation should mention this, but it doesn’t.
After this you would want to run `termux-reload-settings` from the shell. Just an added note: I rarely run termux or edit on it with my thumbs, you can use a program called scrcpy to mess around with it with an actual keyboard.
I think your next issue “Not found; no service started” could easily be related to the allow-external-apps flag not being activated in termux, but not necessarily. If you’re using the latest github or F-droid version of Termux you can extract the Termux’s AndroidManifest.xml file and try running the command with the `--user 0` flag and check it with the following commands:
Code: Select all
adb shell 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' \
--es com.termux.RUN_COMMAND_SESSION_ACTION '0'
There could be an issue with the intent filter. I am going to try and reproduce the issue on my end by modifying your manifest file and see if I get the same issue.
If you want to try and debug at runtime (which is what I’ll be doing) on a development instance you can run:
Code: Select all
adb shell pm grant <your_package_name> com.termux.permission.RUN_COMMAND
and see what you get.
I don’t know what your code actually looks like, but Id imagine you could edit some of it with similar logic:
Code: Select all
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_RUN_COMMAND_PERMISSION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// Request the com.termux.permission.RUN_COMMAND permission
if (ActivityCompat.checkSelfPermission(this, "com.termux.permission.RUN_COMMAND")!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{"com.termux.permission.RUN_COMMAND"}, REQUEST_RUN_COMMAND_PERMISSION);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_RUN_COMMAND_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted, you can now use the com.termux.permission.RUN_COMMAND permission
} else {
// Permission denied, you cannot use the com.termux.permission.RUN_COMMAND permission
}
}
}
}
Do you mind giving some clarification on on your step 3? Does it show the actual permission there, just un-selectable or greyed-out?
I think if it shows up there, there’s no problems with your code. The most likely culprit is what I mentioned in your step one. But maybe not. I would check the system logs to see if there are any error messages related to permission granting.
This can eliminate the possibility that it is a system issue as opposed to a block on the termux side- which I suspect it is.
`adb → dumpsys package`
`adb → pm list permissions`
Lastly, ...RunCommandService isnt classed as an activity (also missing from the docs) its a service, so you’d need to use the `startService()` method. It can be started using an intent but certain extras need to be included in the intent.
I’ll try to give a generalized example.
Code: Select all
Intent intent = new Intent("com.termux.RUN_COMMAND");
intent.setComponent(new ComponentName("com.termux", "com.termux.app.RunCommandService"));
intent.putExtra("com.termux.RUN_COMMAND_PATH", "/data/data/com.termux/files/usr/bin/top");
intent.putExtra("com.termux.RUN_COMMAND_ARGUMENTS", "-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);
Or in TC v 3.30 in the button functionality you can try the settings below: (Im not sure if this is correct but you’d know more about this than I do) For one, I’m not sure if the syntax of `>>` or using ‘service:com.termux/com.termux.app.RunCommandService’ is the proper way. I will test all of this when I patch the manifest and report back with issues. Feel free to PM me as well.
Code: Select all
service:com.termux/com.termux.app.RunCommandService
stream:content://com.termux/files/usr/bin/top
extra:com.termux.RUN_COMMAND_PATH:/data/data/com.termux/files/usr/bin/top
extra:com.termux.RUN_COMMAND_ARGUMENTS:-n,5
extra:com.termux.RUN_COMMAND_WORKDIR:/data/data/com.termux/files/home
extra:com.termux.RUN_COMMAND_BACKGROUND:falseextra:com.termux.RUN_COMMAND_SESSION_ACTION:0