我如何检查Android设备是否已植根?我使用以下代码:
Process proc = Runtime.getRuntime ().exec ("su");
Run Code Online (Sandbox Code Playgroud)
当我在设备上运行它时,我得到了以下异常.
Causes by:Permission denied
Run Code Online (Sandbox Code Playgroud)
但是在模拟器上运行不会给出任何异常.
我正在使用另一种方式来检查.输入adb shell模拟器的命令行返回#,但是对于设备写入adb shell会出现以下错误:
shell@android:/ $ su
su
/system/bin/sh: su: not found
127|shell@android:/ $
Run Code Online (Sandbox Code Playgroud)
那么如何检查设备是否已植根.
提前致谢.
我用这个课:
private void CheckRoot()
{
Process p;
try {
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"Do I have root?\" >/data/LandeRootCheck.txt\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() == 0) {
// TODO Code to run on success
this.IsRoot=true;
}
else {
// TODO Code to run on unsuccessful
this.IsRoot=false;
}
} catch (InterruptedException e) {
// TODO Code to run in interrupted exception
toastMessage("not root");
}
} catch (IOException e) {
// TODO Code to run in input/output exception
toastMessage("not root");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11951 次 |
| 最近记录: |