Search code examples
androidsu

Using su to copy/move a file


I'm pulling out my hair trying to get a copy or move of a file to work using su.

I've tried:

 Runtime.getRuntime().exec("su -c cat " + sourceLocation.getAbsolutePath() + " > " + targetLocation.getAbsolutePath());

and

 Runtime.getRuntime().exec("su cp " + sourceLocation.getAbsolutePath() + " " + targetLocation.getAbsolutePath());

I'm sure I'm missing something stupid and obvious, but I can't pin it down.

Also, is there any way to request SU one time for all my processes? Each time I use it, it's triggering another dialogue.


Solution

  • Root tools takes care of the trickiness.

     CommandCapture command = new CommandCapture(0, "cp -f " + sourceLocation + " " + targetLocation);
     RootTools.getShell(true).add(command);