Android手机获取root权限并实现关机重启功能的方法
本文实例讲述了Android手机获取root权限并实现关机重启功能的方法,是Android程序设计中非常常见的重要功能。现分享给大家,供大家在Android程序开发中参考之用。
具体功能代码如下:
/*
*执行命令
*@paramcommand
*1、获取root权限"chmod777"+getPackageCodePath()
*2、关机reboot-p
*3、重启reboot
*/
publicstaticbooleanexecCmd(Stringcommand){
Processprocess=null;
DataOutputStreamos=null;
try{
process=Runtime.getRuntime().exec("su");
os=newDataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}catch(Exceptione){
returnfalse;
}finally{
try{
if(os!=null){
os.close();
}
if(process!=null){
process.destroy();
}
}catch(Exceptione){
e.printStackTrace();
}
}
returntrue;
}
希望本文所述实例对大家的Android程序设计起到一定的帮助作用。
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短