From: Reimar Döffinger Date: Sun, 13 Mar 2016 15:46:10 +0000 (+0100) Subject: Work around Android crash bug in getExternalFilesDir. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=fff1803c98e359bd7b3caf5d0215291b107cdc78 Work around Android crash bug in getExternalFilesDir. This seems to happen in some cases when there is no SD card. --- diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index 3c351d9..99e3088 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -409,7 +409,11 @@ public class DictionaryApplication extends Application { if (dictDir.isDirectory() && dictDir.list().length > 0) { return dir; } - File efd = getApplicationContext().getExternalFilesDir(null); + File efd = null; + try { + efd = getApplicationContext().getExternalFilesDir(null); + } catch (Exception e) { + } if (efd != null) { efd.mkdirs(); if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { diff --git a/src/com/hughes/android/dictionary/PreferenceActivity.java b/src/com/hughes/android/dictionary/PreferenceActivity.java index 2d66bf9..4481f46 100644 --- a/src/com/hughes/android/dictionary/PreferenceActivity.java +++ b/src/com/hughes/android/dictionary/PreferenceActivity.java @@ -104,7 +104,11 @@ public class PreferenceActivity extends android.preference.PreferenceActivity dirs += "\n" + f.getAbsolutePath(); } } else { - File efd = getApplicationContext().getExternalFilesDir(null); + File efd = null; + try { + efd = getApplicationContext().getExternalFilesDir(null); + } catch (Exception e) { + } if (efd != null) { String externalFilesDir = efd.getAbsolutePath(); if (new File(externalFilesDir).canWrite())