Kamran
Kamran

Reputation: 387

execute ADB command directly in android app

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.

Upvotes: 2

Views: 2394

Answers (2)

Andrii Kovalchuk
Andrii Kovalchuk

Reputation: 4897

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");
        }

Upvotes: 2

andreasperelli
andreasperelli

Reputation: 1034

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.

Upvotes: 0

Related Questions