An example of this article describes the Android phone to get root permissions and to achieve shutdown restart function is a very common in the Android design of the important function. We are now sharing it with you for your reference in the development of Android programs.
The specific function code is as follows:
* *
@param command *
1, get root permission "chmod 777" +getpackagecodepath ()
* 2, Shutdown reboot-p
* 3, Reboot Rebo OT
*
/public static Boolean ExecCmd (String command) {
process process = null;
DataOutputStream OS = null;
try {
process = Runtime.getruntime (). EXEC ("su");
OS = new DataOutputStream (Process.getoutputstream ());
Os.writebytes (command+ "\ n");
Os.writebytes ("exit\n");
Os.flush ();
Process.waitfor ();
} catch (Exception e) {return
false;
} finally {
try {
if (OS!= null) {
os.close ();
}
if (process!= null) {
Process.destroy ();
}
catch (Exception e) {
e.printstacktrace ();
}
} return
true;
}
I hope that the example mentioned in this article will help us to design the Android program.