diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java
index 596a5141..616e678a 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java
@@ -7,11 +7,16 @@ import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.support.v4.content.LocalBroadcastManager;
+import android.widget.Toast;
+import java.io.IOException;
import java.util.List;
+import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
+import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
+import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GENDER;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
@@ -80,6 +85,26 @@ public class SettingsActivity extends AbstractSettingsActivity {
});
+ pref = findPreference("log_to_file");
+ pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newVal) {
+ if (Boolean.TRUE.equals(newVal)) {
+ try {
+ FileUtils.getExternalFilesDir(); // ensures that it is created
+ } catch (IOException ex) {
+ GB.toast(getApplicationContext(),
+ getString(R.string.error_creating_directory_for_logfiles, ex.getLocalizedMessage()),
+ Toast.LENGTH_LONG,
+ GB.ERROR,
+ ex);
+ }
+ }
+ return true;
+ }
+
+ });
+
// Get all receivers of Media Buttons
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3d60e89a..fb65429d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -233,5 +233,6 @@
An alarm was set for %1$02d:%2$02d
HW: %1$s
FW: %1$s
+ Error creating directory for log files: %1$s