Skip to content Skip to sidebar Skip to footer

How To Run Root Commands From Android Application?

I want to write an application which roots the device on which it is installed, I mean by installing this app you will be able to root your device without a computer, just like th

Solution 1:

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) {
        os.writeBytes(tmpCmd+"\n");
    }           
    os.writeBytes("exit\n");  
    os.flush();
}

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/bootanimation.zip", "sysro"};


Post a Comment for "How To Run Root Commands From Android Application?"