Skip to content

Commit

Permalink
Issue #660 - Catch Android NPE in Environment.getExternalStorageState()
Browse files Browse the repository at this point in the history
  • Loading branch information
nostra13 committed Jul 8, 2014
1 parent e56bc0d commit 54a9038
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ public static File getCacheDirectory(Context context) {
*/
public static File getCacheDirectory(Context context, boolean preferExternal) {
File appCacheDir = null;
if (preferExternal && MEDIA_MOUNTED
.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
String externalStorageState;
try {
externalStorageState = Environment.getExternalStorageState();
} catch (NullPointerException e) { // (sh)it happens (Issue #660)
externalStorageState = "";
}
if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
appCacheDir = getExternalCacheDir(context);
}
if (appCacheDir == null) {
Expand Down

0 comments on commit 54a9038

Please sign in to comment.