android实现自动关机的具体方法
程序员文章站
2024-02-09 23:16:46
[java] 复制代码 代码如下:private void shutdown() { &...
[java]
private void shutdown() {
try {
process process = runtime.getruntime().exec("su");
dataoutputstream out = new dataoutputstream(
process.getoutputstream());
out.writebytes("reboot -p\n");
out.writebytes("exit\n");
out.flush();
} catch (ioexception e) {
e.printstacktrace();
}
}
private void shutdown() {
try {
process process = runtime.getruntime().exec("su");
dataoutputstream out = new dataoutputstream(
process.getoutputstream());
out.writebytes("reboot -p\n");
out.writebytes("exit\n");
out.flush();
} catch (ioexception e) {
e.printstacktrace();
}
}
note:手机必须获取root权限!!!
复制代码 代码如下:
private void shutdown() {
try {
process process = runtime.getruntime().exec("su");
dataoutputstream out = new dataoutputstream(
process.getoutputstream());
out.writebytes("reboot -p\n");
out.writebytes("exit\n");
out.flush();
} catch (ioexception e) {
e.printstacktrace();
}
}
private void shutdown() {
try {
process process = runtime.getruntime().exec("su");
dataoutputstream out = new dataoutputstream(
process.getoutputstream());
out.writebytes("reboot -p\n");
out.writebytes("exit\n");
out.flush();
} catch (ioexception e) {
e.printstacktrace();
}
}
note:手机必须获取root权限!!!