Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 + "
");
os.flush();
os.writeBytes("exit
");
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!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...