Sorry for slow response, I hadn't been at a PC for a while. I'm glad you were able to get some of it working using the github version. I wish I had mentioned it earlier!Thanks, that was the important factor to get it to work! The Play Store version did not work AT ALL with 3rd party apps:
In regards to the error message you're seeing, your suspicions are correct. The `com.termux.permission.RUN_COMMAND` permission is required to start the `RunCommandService`
as you know, the app that executees the `adb shell` commands is the ADB itself, however, ADB doesn't have a package name or a UI component that can request permissions.
you can try granting it with
Code: Select all
adb shell pm grant com.termux android.permission.INTERACT_ACROSS_USERS
if that doesn't work you could try using the `--user 0` flag with the `am startservice` command:
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'
permission to the `com.android.adb` package like so:
Code: Select all
adb shell pm grant com.android.adb com.termux.permission.RUN_COMMAND
You are correct, this is due to the way Android handles background services and permissions after 8.0. When the Termux service is stopped, and its process is terminated, you can't start it from the background when the app is not in the foreground without the users knowledge (usually through a popup)My guess is that it happens because the Termux service isn't running when Termux itself isn't running. I have to start both Termux and Total Commander manually to be able to send commands from Total Commander to Termux.
The `checkSelfPermission(termuxPermission)` method returning `PackageManager.PERMISSION_GRANTED` is not relevant in this case, as the permission check is not the issue. The problem is that the Termux service is not running, and your app is trying to start it from the background.
you could any of the following to resolve this:
As you've already discovered, starting both Termux and Total Commander manually allows you to send commands from Total Commander to Termux.
You can modify your app to use a foreground service, which can run even when the app is not in the foreground. However, this requires displaying a notification to the user, indicating that the service is running.
You can try using a workaround, such as starting Termux using an `am start` command, like this:
Code: Select all
adb shell am start -n com.termux/.app.TermuxActivity