From 029b4a7b0270f456ba09415a858035020bff94b1 Mon Sep 17 00:00:00 2001 From: Jamorham Date: Mon, 19 Sep 2016 21:51:58 +0100 Subject: [PATCH] Import database fix --- .../dexdrip/ImportDatabaseActivity.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java index 6fe0b7fb52..e4c3ba51d3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java @@ -11,6 +11,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; @@ -18,6 +19,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; +import com.eveningoutpost.dexdrip.Models.JoH; import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; import com.eveningoutpost.dexdrip.utils.DatabaseUtil; import com.eveningoutpost.dexdrip.utils.FileUtils; @@ -36,6 +38,7 @@ public class ImportDatabaseActivity extends ListActivityWithMenu { private Handler mHandler; private ArrayList databaseNames; private ArrayList databases; + private final static int MY_PERMISSIONS_REQUEST_STORAGE = 132; @Override protected void onCreate(Bundle savedInstanceState) { @@ -54,9 +57,10 @@ private void generateDBGui() { sortDatabasesAlphabetically(); showDatabasesInList(); } else if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + JoH.static_toast_long("Need permission for saved files"); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - 0); + MY_PERMISSIONS_REQUEST_STORAGE); } else { postImportDB("\'xdrip\' is not a directory... aborting."); } @@ -137,8 +141,9 @@ public boolean accept(File pathname) { return pathname.getPath().endsWith(".sqlite"); } }); - - Collections.addAll(databases, files); + if ((databases != null) && (files != null)) { + Collections.addAll(databases, files); + } } @Override @@ -173,6 +178,18 @@ public String getMenuName() { return menu_name; } + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == MY_PERMISSIONS_REQUEST_STORAGE) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + generateDBGui(); + } else { + finish(); + } + } + } + public int getDBVersion() { int version = -1;