Why mkdirs() sometimes returns false - error creating foler

36 Views Asked by At

I get crashes on my App. I see them in Crashlytics (couldn't reproduce on my devices).

The problem - can't create folder in External Storage using mkdirs()

Note: the code works in 99% of cases (users) and the problem appears only in 1%.

I do have a manifest permission as well I do ask for runtime permissions.

The problem appears mostly on Android 5 versions (so runtime permissions are probably not the issue)

My code:

String pathTemp = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "MyApp"
File folderTemp = new File(pathTemp);
if (!folderTemp.mkdirs() && !folderTemp.exists()) {
        throw new AssertionError("Error creating temp folder");
}

The crash statistics: enter image description here

0

There are 0 best solutions below