Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ public static File getExternalStorageDir(Context context, boolean forcePrivate,
}
if ((!legacy && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) || forcePrivate) {
// Q no longer allows using getExternalStorageDirectory()
return context.getExternalFilesDir(null);
File externalStorage = context.getExternalFilesDir(null);
if (externalStorage == null) {
// This can happen if the external storage is not currently mounted, but we need some
// place to put assets, etc. Fall back to internal storage in this case.
return context.getFilesDir();
} else {
return externalStorage;
}
} else {
return Environment.getExternalStorageDirectory();
}
Expand Down