android 判斷app是否具有root許可權
阿新 • • 發佈:2018-12-18
應用判斷是否具有root許可權,只需要看能否在data分割槽建立檔案,如果能夠在data分割槽建立檔案,那麼應用具有root許可權
Process process = null;
DataOutputStream os = null;
try {
Log.i("roottest", "try it");
process = Runtime.getRuntime().exec("su"); //切換到root帳號
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
process.waitFor();
} catch (Exception e) {
return false;
} finally {
try {
if (os != null) {
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}