简体   繁体   中英

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 which 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 getExternalStorageDirectory() returns /storage/emulated/0/ as path, on which 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM