I have searched on Stack Overflow already and basically answers are all using Environment.getExternalStorageDirectory()
to get the sd card dir.
However, in my phone it always give me /storage/emulated/0
, which seems like the internal storage (not the real sd card), while I need a path like /storage/6265-6530
which is the actual sd card. I have checked my sd card path is /storage/6265-6530
in android studio.
I tried to create a folder directly using
File file = new File("/storage/6265-6530/MyApp/");
boolean result = file.mkdirs();
But the result is always false
.
I have granted all permission like android.permission.WRITE_EXTERNAL_STORAGE
and request the permission in run time. But still get the error above.
While I tried to create a folder in /storage/emulated/0
and it is ok, like below.
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyApp/");
boolean result = file.mkdirs();
and the created path will be: "/storage/emulated/0/MyApp"
I have also tried to get sd card directory using below:
File[] fs = reactContext.getExternalFilesDirs(null);
fs[1].getAbsolutePath()
but I can only get the application-specific directories in sd card, like /storage/6265-6530/Android/data/<my application package>/files
, not the root path of sd card.
How can I have access to write files/create folders in root path of sd card? eg. /storage/6265-6530/
My android version is 7.
Thanks