mkdirs returns false in some device

72 Views Asked by At

This code works for me but it is reported in fabric crashlytics not work on some devices and actually mkdirs retrun false I checked already the dir.exists() before .

File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/Gahvare/");
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                Crashlytics.logException(new Exception("in downloadFileWithProgressBar directory not exist, path: " + dir.getPath() + "  absolut path is :" + dir.getAbsolutePath()));
                //  callback.onFailure(CONNECTION_ERROR);
            }
        }

fabric report

device list not workdevice list not work

1

There are 1 best solutions below

1
Shanmuka Chowdary On

Try below in application manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.appname" 
    android:versionCode="1"
    android:versionName="0.2">

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />