龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 移动开发 > Android开发 >

android实现自动关机的具体方法

时间:2014-06-16 15:44来源:网络整理 作者:网络 点击:
分享到:
android实现自动关机的具体方法,需要的朋友可以参考一下
[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权限!!!
精彩图集

赞助商链接