android获取root代码,Android获取ROOT权限的实例代码
獲取android的root權限其實很簡單,只要在runtime下執行命令"su"就可以了。
// 獲取root權限
public void get_root(){
if (is_root()){
toast.maketext(mctx, "已經具有root權限!", toast.length_long).show();
}
else{
try{
progress_dialog = progressdialog.show(mctx,
"root", "正在獲取root權限...", true, false);
runtime.getruntime().exec("su");
}
catch (exception e){
toast.maketext(mctx, "獲取root權限時出錯!", toast.length_long).show();
}
}
}
其中is_root()判斷是否已經具有了root權限。只要/system/bin/su、/system/xbin/su這兩個文件中有一個存在,就表明已經具有root權限,如果兩個都不存在,則不具有root權限。
// 判斷是否具有root權限
public static boolean is_root(){
boolean res = false;
try{
if ((!new file("/system/bin/su").exists()) &&
(!new file("/system/xbin/su").exists())){
res = false;
}
else {
res = true;
};
}
catch (exception e) {
}
return res;
總結
以上是生活随笔為你收集整理的android获取root代码,Android获取ROOT权限的实例代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eval()解析JSON
- 下一篇: ASP.NET MVC URL重写与优化