Skip to content

Commit 54a9038

Browse files
committedJul 8, 2014
Issue nostra13#660 - Catch Android NPE in Environment.getExternalStorageState()
1 parent e56bc0d commit 54a9038

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎library/src/com/nostra13/universalimageloader/utils/StorageUtils.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ public static File getCacheDirectory(Context context) {
6565
*/
6666
public static File getCacheDirectory(Context context, boolean preferExternal) {
6767
File appCacheDir = null;
68-
if (preferExternal && MEDIA_MOUNTED
69-
.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
68+
String externalStorageState;
69+
try {
70+
externalStorageState = Environment.getExternalStorageState();
71+
} catch (NullPointerException e) { // (sh)it happens (Issue #660)
72+
externalStorageState = "";
73+
}
74+
if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
7075
appCacheDir = getExternalCacheDir(context);
7176
}
7277
if (appCacheDir == null) {

0 commit comments

Comments
 (0)
Please sign in to comment.