我可以轻松地从 adb shell 使用 'rm /data/system/[file]' 但从应用程序这不起作用。
命令“du”、“ls”、“echo”在代码中工作正常,但命令“rm”不起作用。它甚至不适用于 sdcard。
我试过的代码:
1)
String[] cmd = { "/system/bin/sh", "-c", "rm -r /sdcard/1" };
try {
Process process = Runtime.getRuntime().exec(cmd);//execute command
//read the output of command
InputStreamReader reader = new InputStreamReader(process.getInputStream());
.....
2) 与 (1) 相同的代码,用“su”代替“/system/bin/sh”
3)
process=Runtime.getRuntime().exec("/system/bin/sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("rm -r /sdcard/1\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
4) 与 (3) 相同的代码,用 'su' 代替 '/system/bin/sh'