Home » Android » Run android program as root

Run android program as root

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&Answers:

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