我根植了设备并安装了busybox。现在我想通过我的应用程序访问/ data文件夹文件。我的应用程序具有超级用户权限,但我仍然无法访问文件。 任何人都可以知道如何做到这一点(有或没有busybox)?
请帮帮我。
代码:
if ((new File("/data/bin/su")).exists())
SU_COMMAND = "/data/bin/su";
else
SU_COMMAND = "su";
String command1 = "busybox mount /sdcard \n";
String command2 = "busybox mount /system \n";
String command = "busybox cp /data/data/com.my.test.app/databases/ /mnt/sdcard/testapp/ \n";
Process process = (new ProcessBuilder(as)).start();
Runtime rt = Runtime.getRuntime();
java.io.OutputStream outputstream = process.getOutputStream();
outputstream.write(command1.getBytes());
outputstream.flush();
答案 0 :(得分:4)
试试这个:
private boolean run(boolean runAsRoot, String cmd) {
String shell = runAsRoot ? "su" : "sh";
int exitCode = 255;
Process p;
try {
p = Runtime.getRuntime().exec(shell);
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmd + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
exitCode = p.waitFor();
} catch (IOException e1) {
Log.e("Exception", e1.toString());
} catch (InterruptedException e) {
Log.e("Exception", e.toString());
}
return (exitCode != 255);
}
public boolean copyFile() {
return run(true, "busybox cp /data/data/com.my.test.app/databases/ /mnt/sdcard/testapp/");
}