【发布时间】:2016-08-02 11:34:46
【问题描述】:
我有 root 权限,我正在为我的应用测试一项新功能,该功能涉及访问和编辑 Android 的系统文件夹。
但是我的代码似乎没有改变任何东西。我在Marshmallow CM 13.
Process p;
try {
// Preform su to get root privileges
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?\" >/system/etc/temporary.txt\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
// TODO Code to run on success
toastMessage("root");
}
else {
// TODO Code to run on unsuccessful
toastMessage("not root");
}
} 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");
}
【问题讨论】:
-
而是先尝试打印权限
-
@Shriram 通过 adb shell?