Access /data folder files in android
I have rooted my device and I have install busybox. Now I want to access /data folder files through my application. My application have super user permissions but still I am not able to access file . Can any one know how to do this (with or without busybox)?
Ple开发者_高级运维ase help me.
Code:
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();
Try out this one:
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/");
}
精彩评论