From f105bbbde354b4b41188f7fdd4c784709fd906ed Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 21 Jun 2015 10:18:41 +0200 Subject: [PATCH] Avoid crash when getExternelDir() returns null (huh!) --- .../gadgetbridge/GBApplication.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 0f42713e9..a512087e5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.os.Build; import android.os.Build.VERSION; import android.preference.PreferenceManager; +import android.util.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,11 +48,17 @@ public class GBApplication extends Application { private void setupLogging() { if (isFileLoggingEnabled()) { File dir = getExternalFilesDir(null); - if (dir != null && !dir.exists()) { - dir.mkdirs(); + if (dir != null) { + if (!dir.exists()) { + dir.mkdirs(); + } + // used by assets/logback.xml since the location cannot be statically determined + System.setProperty("GB_LOGFILES_DIR", dir.getAbsolutePath()); + } else { + Log.e("GBApplication", "External files dir is null, cannot log to file"); + System.setProperty("GB_LOGFILES_DIR", "/dev/null"); + } - // used by assets/logback.xml since the location cannot be statically determined - System.setProperty("GB_LOGFILES_DIR", dir.getAbsolutePath()); } else { System.setProperty("GB_LOGFILES_DIR", "/dev/null"); // just to please logback configuration, not used at all try {