How to run root commands from Android application?

To run root commands, you have to use the following format:

public void RunAsRoot(String[] cmds){
    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(p.getOutputStream());            
    for (String tmpCmd : cmds) {

where you pass in an array of strings, each string being a command that needs to be executed. For example:

String[] cmds = {"sysrw", "rm /data/local/", "sysro"};

Leave a Comment