From 70cd3a7960b33021ac02c8fe8c52d0655cff8be6 Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Sun, 25 Sep 2016 17:09:41 +0100 Subject: [PATCH] Added fallback and toast if android app can't write to desired directory --- res/values/strings.xml | 1 + src/org/kiwix/kiwixmobile/downloader/DownloadService.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/res/values/strings.xml b/res/values/strings.xml index ce9522496..5cc25effe 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -141,4 +141,5 @@ We are glad to have you on board and would appreciate any feedback or suggestions. Storage Current Folder + Can't access desired directory, using default. To fix this reselect the desired directory in app settings. diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java index 2ed5f4233..af5c23781 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java @@ -20,6 +20,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; import android.util.Log; import android.util.Pair; +import android.widget.Toast; import java.io.File; import java.io.IOException; @@ -90,6 +91,7 @@ public class DownloadService extends Service { .getString(KiwixMobileActivity.PREF_STORAGE,Environment.getExternalStorageDirectory().getPath()); KIWIX_ROOT = SD_CARD + "/Kiwix/"; + KIWIX_ROOT = checkWritable(KIWIX_ROOT); notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE); LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book"); @@ -129,6 +131,12 @@ public class DownloadService extends Service { notificationManager.cancel(notificationID); } + public String checkWritable(String path){ + if (new File(path).canWrite()) + return path; + Toast.makeText(this, getResources().getString(R.string.path_not_writable), Toast.LENGTH_LONG).show(); + return Environment.getExternalStorageDirectory().getPath(); + } public void pauseDownload(int notificationID) { downloadStatus.put(notificationID, 1);