Reputation: 57
In my root-required android application I need to be able to copy files to and from the SD Card. In most cases root permission is needed. The issue I've come across is that
cp -fp <source> <destination>
doesn't work when <destination>
or <source>
contains Environment.getExternalStorageDirectory()
Reading the logs, I noticed that it was failing with No such file or directory
However, when copying to the SD Card, I've ensured that the directory is created in the function before running the command in the shell, and when copying from the SD Card, the file exists.
Is there another way to copy files in the shell (I've tried cp
, busybox cp
and cat
)?
Or is there another way to get the direct path to the location of my files on the SD Card?
Upvotes: 0
Views: 2371
Reputation: 57
Actually managed to solve this mere moments after I asked the question. For information Environment.getExternalStorageDirectory()
was returning /storage/emulated/0/
By replacing Environment.getExternalStorageDirectory()
with /sdcard/
Everything worked properly.
EDIT 1:
Replacing Environment.getExternalStorageDirectory()
with /sdcard/
causes device restrictions (as pointed out by shoe rat below). Sifting through android.os.Environment
landed me with another usable alternative System.getenv("EXTERNAL_STORAGE")
. Everything still works exactly as it should.
Upvotes: 1