Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path of getExternalStoragePublicDirectory on Samsung Galaxy Note

Tags:

android

galaxy

In my app, I am creating files which are stored in the devices Downloads directory. All of my users are happy with this mechanism... except the ones using a Samsung Galaxy Note.

It's kind of hard to debug without owning such a device. Within my code, I am using

File newFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "file01");
    if (newFile.exists()) {
        // show error
    } else {
        if (!newFile.mkdirs()) {
            // show error
        }
    }

to find the path for the target directory. On the Galaxy Note, the path returned is "/storage/sdcard0/Download". However, on the local file system directory is written in lowercase ("download") and the files created by my app do not obviously not exist on the local file directory. At least my users complain about this. I assume the problem to be related with the lowercase/uppercase difference in the path.

Does anybody have an idea why this works on all devices except the Galaxy Note?

Thanks!

like image 747
EricJobs Avatar asked Mar 18 '14 15:03

EricJobs


People also ask

What can I use instead of getExternalStoragePublicDirectory?

For api 28 and below, you need getExternalStoragePublicDirectory() method but it is deprecated. What if you don't want to use that deprecated method? Then you can use SAF file explorer(Intent#ACTION_OPEN_DOCUMENT). As said in the question, this requires the user to pick the location manually.

What is absolute path in Android?

An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport is an absolute path.


1 Answers

There is no guarantee that the location returned by getExternalStoragePublicDirectory() actually exists. Yours may be the first app that needs a particular one of those directories. Hence, it is your job to call mkdirs() on that location, on all devices, not just this one.

Beyond that, as to why somebody else (Samsung or another third-party app) is creating a lowercase download directory, the only way to determine "why" is to figure out who created that directory and then contact that developer. This is unlikely to be a worthwhile investment in time.

So long as you are calling mkdirs() to create Download, whatever other directories that may exist are not really your concern. If you wanted to detect possible collisions like this, and warn the user, you could do that, though I have no idea if that would be worthwhile.

like image 172
CommonsWare Avatar answered Sep 23 '22 10:09

CommonsWare