getExternalFilesDir(null) returns null

If this wasn't a typo when you posted your question, you'll probably hate yourself for this:

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

should be

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


This is from Android documentation:

Returns the path of the directory holding application files on external storage. Returns null if external storage is not currently mounted so it could not ensure the path exists; you will need to call this method again when it is available.

The other option is you can check if External storage is available:

String state = Environment.getExternalStorageState();
File filesDir;

// Make sure it's available
if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    filesDir = getExternalFilesDir(null);
} else {
    // Load another directory, probably local memory
    filesDir = getFilesDir();
}

Tags:

Android