Run Linux commands on android
Process localProcess = runtime.getruntime(cmd.exe c (su );
This Code grants root privileges.
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;
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 call localProcess. 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.