0

i'm tring to copy one file by one directory to another. i'm using the "cp" function. this is the code

Process process = Runtime.getRuntime().exec("cp "+path+" "+destinationFolder);

this code work well on many device but in other i get this error

error running exec(cp, /data/app/myApp.apk, mnt/sdcard/destinationFolder.

working directory null, envinroment null. caused by ioException permission denied why i'm getting this error and how can i solve? any help is

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Giovanni Mariotti
  • 615
  • 1
  • 7
  • 11
  • Well... here's a workaround: copy the file [programmatically](http://stackoverflow.com/questions/12496732/copy-file-from-the-directory-to-another-having-the-paths-of-file-and-director) – Phantômaxx Jan 03 '14 at 19:18

2 Answers2

1

error running exec(cp, /data/app/myApp.apk, mnt/sdcard/destinationFolder

Looks your destination path lacks root slash as it should be /mnt/sdcard/destinationFolder not mnt/sdcard/destinationFolder as quoted error message indicates

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • And not sure how you build destinationFolder really, but you should be using `getExternalStorageDirectory()`: https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory() – Marcin Orlowski Jan 03 '14 at 20:10
  • No, this not solve the problem. but the command "cp" require root access? – Giovanni Mariotti Jan 03 '14 at 20:15
0

This error could be vendor dependant, obviously the error is lack of permissions when trying to copy the files in /data/app/, most of the devices won't let you do that unless the device is rooted and you are using sudo commands, if you are trying to attack a global market with your application I'm sure you will have a lot of problems with that, and you should find a better approach.

Hope this Helps

Regards!

Martin Cazares
  • 13,637
  • 10
  • 47
  • 54
  • If you are trying to copy a file that requires root permissions yes, otherwise no, that's why it might work on some phones because some vendors might have different permissions stated – Martin Cazares Jan 03 '14 at 20:25
  • i'm tring to copy an apk file by it's folder to another folder in sdcard. this require root access? – Giovanni Mariotti Jan 03 '14 at 20:29
  • It might, but now that you mention it, are you sure you have the "android.permission.WRITE_EXTERNAL_STORAGE" set in your manifest? – Martin Cazares Jan 03 '14 at 20:32
  • Yes, this permessions is set in my manifest. i don't understand if the cp function require root access or not. i tested on my rooted phone and it works but in NON rooted phone i get the error that is in the question, so this "cp" command require root access? – Giovanni Mariotti Jan 03 '14 at 20:35
  • cp will require root access IF and only IF the file you are trying to copy requires root permissions, is not the command "cp" itself the one that needs the permissions but the file you are trying to copy – Martin Cazares Jan 03 '14 at 21:55