在adb shell命令下:reboot实现系统重启,reboot -p实现系统关机
代码中实现如下:
public void ShutDownByRuntime()
{Process proc;
String result= "";
try {
Process process = null;
InputStream instream = null;
BufferedReader bufferReader = null;
process = Runtime.getRuntime().exec("/system/bin/reboot -p\n");
instream = process.getInputStream();
bufferReader = new BufferedReader(new InputStreamReader(instream, "GBK"));
String readline;
while ((readline = bufferReader.readLine()) != null) {
result = result+readline;
// Log.i(TAG, "execute command result : " + readline);
}
int status = process.waitFor();
Toast.makeText(getApplicationContext(), result,Toast.LENGTH_LONG);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //关机
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}