I'm using a Samsung A3, Android 5.0.2. I'm using this setup to compile apps, i.e. Android 4.1 Jelly Bean (API 16) target.
I precisely know the path of the external removable microSD card, it is /mnt/extSdCard/
(see also Note #7 below).
Problem: I notice that
File myDir = new File("/mnt/extSdCard/test");
myDir.mkdirs();
doesn't work: no directory is created.
Also:
File file = new File("/mnt/extSdCard/books/test.txt"); // the folder "books" already exists on the external microSD card, has been created from computer with USB connection
FileOutputStream fos = new FileOutputStream(file);
produces this error:
java.io.FileNotFoundException: /mnt/extSdCard/books/test.txt: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(...
How to force read+write access to external removable microSD card?
Notes:
Environment.getExternalStorageDirectory().toString()
gives/storage/emulated/0
which is my phone internal storage, i.e. not what I want.getExternalFilesDir(null)
gives/storage/emulated/0/Android/data/com.blahblah.appname/files/
i.e. not what I want. Note that I can't usegetExternalFilesDirs
with a finals
because this is not available in API16. Also runtime permissions are not available in API16 neither.I already have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
, and alsoREAD_EXTERNAL_STORAGE
.I read lots of topics like this one or this one, in fact probably twenty similar questions, but finally it seems very complex and everything and its contrary is said. That's my I'm looking for a solution specific to this situation.
I don't want
ACTION_OPEN_DOCUMENT
andACTION_CREATE_DOCUMENT
, in fact I don't want any GUI solution.Some apps I have (Sync Resilio) are allowed to modify
/mnt/extSdCard/music/
successfully, to create new files there, etc.By the way,
ls -la /mnt/extSdCard/
givesdrwxrwx--x root sdcard_r 2017-10-15 01:21 Android drwxrwx--- root sdcard_r 2017-10-14 00:59 LOST.DIR drwxrwx--- root sdcard_r 2017-12-05 16:44 books drwxrwx--- root sdcard_r 2017-11-21 22:55 music