Path of getExternalStoragePublicDirectory on Samsung Galaxy Note

时间秒杀一切 提交于 2019-12-04 01:11:31

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/22484278/path-of-getexternalstoragepublicdirectory-on-samsung-galaxy-note

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!