2

I want to execute adb commands like adb backup -noapk com.your.packagename directly in my android app.

How can I do it? Is it possible or do I have to use an Android API?


I want to write an Android app using Java and be able to run it as if I had a terminal with adb in it.

1
  • i believe you need superuser permission to run adb shell commands..but to to have SU access, one must root the device...
    – Vny Kumar
    Commented Nov 12, 2014 at 10:24

2 Answers 2

2

Try this:

 private void runAdbCommands(String command) {
            ProcessBuilder pb = new ProcessBuilder(command);
            Process pc = null;
            try {
                pc = pb.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                pc.waitFor();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Done");
        }
2
  • I got an exception in the first try-catch block
    – Vlad
    Commented Dec 7, 2018 at 12:24
  • Same to me. I run into Cannot run program "appops set com.abc.assistant SYSTEM_ALERT_WINDOW allow": error=2, No such file or directory
    – hannes ach
    Commented May 5, 2021 at 13:38
0

You want to execute the adb client, and you can't find it in Android system. What is executed in Android is the adb server, in listening for adb clients launched from external OS.

Not the answer you're looking for? Browse other questions tagged or ask your own question.