-3

Now I'm making some version of File Manager in Andoid. My permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

When I write new file to /mnt/sdcard (External Stroage) everything is allright. But When i write new file to /mnt/sdcard2 (internal storage) I get IOException like open failed: EACCES (Permission denied) My full code:

try {
            File existingFile = new File(path);
            File newFile = new File(newPath);
            if (!newFile.exists()) {
                if (!isFolder)
                {
                    newFile.createNewFile();
                }

            } 

            if (isFolder) {
                FileUtils.copyDirectory(existingFile, newFile);
            }
            else
            {
                FileUtils.copyFile(existingFile, newFile);
            }

        } catch (IOException e) {
            result = 1;
        }

When i test my application I use real device. My Path is like '/mnt/sdcard/Music/blabla' and so on

1 Answers1

1

My Path is like '/mnt/sdcard/Music/blabla'

Do not use hardcoded paths as these may (and will) differ depending on device model or can even OS version. You got methods in Environment class to get you root folder of external storage and you should use it like getExternalStorageDirectory()

EDIT

. I need to get folder that contents folder like Music, DCIM, Download, but in Inner Storage of Smartphone

You cannot have "private" DCIM, Downloads really if you want to use system features like DownloadManager or external Camera app, because these apps will simply not be able to write to your private storage. So you either download/take photo yourself - then you can save the file whenever you want, or you use what is it now available, with all the pros and cons.

Name "external"/"internal" is a bit misleading nowadays, so do not take it too literally.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141