adryx_92 adryx_92 - 6 months ago 45
Java Question

Read/write external storage on Android

I'm developing an Android application that reads and writes data in a

/sdcard/MyFolder
directory. I get the sdcard path trough the method
Environment.getExternalStorageDirectory()
.

I tested the application on a Samsung device where the path returned by the method is
/mnt/sdcard
on wich I append
/MyFolder
; all works fine and I can r/w files in this folder.
Now I'm trying to do the same on a Nexus device: I have put my files to read in the
/sdcard/MyFolder
directory and the
getExternalStorageDirectory()
returs
/storage/emulated/0/
as path, on wich I append
/MyFolder
. But in this case I cannot find the files to read.

I set all the storage permissions in the manifest.

Am I doing something wrong? Is there any particular issue related to an emulated directory?

Thanks

Answer

In Android 6.0, you have to handle certain permissions at runtime. Please go through this. Because READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are considered as dangerous permissions and has to be handled at runtime.