Process localprocess = runtime.getruntime(cmd.exe C ("Su ");
ThisCodeGet root permission
Outputstream localoutputstream = localprocess. getoutputstream ();
Dataoutputstream localdataoutputstream = new dataoutputstream (localoutputstream );
Obtain the output stream from the process object, and then we can execute the Linux Command.
Localdataoutputstream. writebytes (string Str );
STR is a variable of the string type. Note that there is a line break at the end of Str.
For example, string STR = "mkdir/mnt/sdcard/zhycheng \ n ";
Inputstream localinputstream = localprocess. getinputstream ();
Datainputstream localdatainputstream = new datainputstream (localinputstream );
The two codes get the output stream.
For example, string out =Localdatainputstream. Readline ();
This is output from the console
Call after each output
Localdataoutputstream. Flush ();
Also callLocalprocess. waitfor ();
Call the test command int I = execrootcmdsilent ("echo test") to determine whether the root permission is obtained. If I is not equal to-1, the root permission is obtained.