artem
artem

Reputation: 16798

Run android program as root

Is it possible to run my program as root? I know how to run command-line native utils, but how to run Java program as root?

Upvotes: 9

Views: 44458

Answers (1)

Tim
Tim

Reputation: 6712

This will work for you:

try {
    Process process = Runtime.getRuntime().exec("su");
    process.waitFor();
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}

You could use this for a command:

exec(new String[] { "su", "-c", COMMAND });

Best wishes, Tim

Upvotes: 13

Related Questions