From 559cd557c274adb83e921b2e77ba204f1a26adee Mon Sep 17 00:00:00 2001 From: Felix Konstantin Maurer Date: Mon, 8 Jan 2018 12:07:10 +0100 Subject: [PATCH] Permissions must be persistet to be reused after boot --- .../gadgetbridge/activities/SettingsActivity.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 f1ec08b88..a7ef7badd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -293,6 +293,7 @@ public class SettingsActivity extends AbstractSettingsActivity { Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT); i.setType("application/x-sqlite3"); i.addCategory(Intent.CATEGORY_OPENABLE); + i.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); String title = getApplicationContext().getString(R.string.choose_auto_export_location); startActivityForResult(Intent.createChooser(i, title), FILE_REQUEST_CODE); return true; @@ -355,9 +356,10 @@ public class SettingsActivity extends AbstractSettingsActivity { } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == FILE_REQUEST_CODE && data != null) { - Uri uri = data.getData(); + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + if (requestCode == FILE_REQUEST_CODE && intent != null) { + Uri uri = intent.getData(); + getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); PreferenceManager .getDefaultSharedPreferences(this) .edit()