欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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权限!!!