Copy folders in /data/data to sdcard & vice-versa

最后都变了- 提交于 2019-11-28 01:22:01

问题


I have a problem when I try to copy folders inside /data/data to SDcard.

I have my phone rooted.

I request Superuser permissions in my app with:

Runtime.getRuntime().exec("su");

I'm using FileUtils from Apache to copy files/folders.

What I discovered is if I manually change the folders permissions to READ I can copy it from /data/data to SDcard.

Is there any way to recursively change the RW permissions of all folders inside /data/data to read and write folders?

I've tried chmod but It doesn't work.

Runtime.getRuntime().exec("chmod 777 /data/data");

I want to do a backup program and i want to read some folders inside /data/data and write them in a SDcard's folder.

Then I want to restore this folders reading them from a SDcard's folder and write them in /data/data.

Could you help me, please?


回答1:


At the end I got it!!!!

I use the SuperUser process with the cp command to copy the files and folders.

I hope you find it helpful.

String comando = "cp -r /data/data/sourcefolder /sdcard/targetfolder";
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes(comando + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
try
{
 int suProcessRetval = suProcess.waitFor();
 if (255 != suProcessRetval)
 {
  // Acceso Root concedido
  retval = true;
 }else
 {
  // Acceso Root denegado
  retval = false;
 }
}
catch (Exception ex)
{
 Log.w("Error ejecutando el comando Root", ex);
}

Thank you very much to all the people of this forum and for all the help which you offer!!



来源:https://stackoverflow.com/questions/10735273/copy-folders-in-data-data-to-sdcard-vice-versa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!