From e370abbb434f6eed44f8dcfc804cb075c73f11b7 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sun, 23 Aug 2020 22:09:13 +0200 Subject: [PATCH] Request storage permission only with APIs <= 28 --- app/src/main/AndroidManifest.xml | 4 ++- .../settings/AccountSettingsFragment.java | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 13390561..9d47cb49 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,9 @@ - + { new MaterialDialog.Builder(getActivity()) .items(R.array.opml_import_export) - .itemsCallback(((dialog, itemView, position, text) -> { - if (position == 0) { - OPMLHelper.openFileIntent(this); - } else { - if (PermissionManager.isPermissionGranted(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) - exportAsOPMLFile(); - else - requestExternalStoragePermission(); - } - })) + .itemsCallback(((dialog, itemView, position, text) -> openOPMLMode(position))) .show(); return true; }); @@ -175,6 +167,22 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat { .show(); } + private void openOPMLMode(int position) { + if (position == 0) { + OPMLHelper.openFileIntent(this); + } else { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { + if (PermissionManager.isPermissionGranted(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + exportAsOPMLFile(); + } else { + requestExternalStoragePermission(); + } + } else { + exportAsOPMLFile(); + } + } + } + // region opml import @Override @@ -243,8 +251,7 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat { displayNotification(fileName, path); } catch (Exception e) { - Log.e(TAG, e.getMessage()); - Utils.showSnackbar(getView(), e.getMessage()); + displayErrorMessage(); } }