Added fallback and toast if android app can't write to desired directory

This commit is contained in:
mhutti1 2016-09-25 17:09:41 +01:00
parent 91823e2a7f
commit 70cd3a7960
2 changed files with 9 additions and 0 deletions

View File

@ -141,4 +141,5 @@
<string name="help_21">We are glad to have you on board and would appreciate any feedback or suggestions.</string>
<string name="pref_storage">Storage</string>
<string name="pref_current_folder">Current Folder</string>
<string name="path_not_writable">Can't access desired directory, using default. To fix this reselect the desired directory in app settings.</string>
</resources>

View File

@ -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);