From ec092aa3454a787f9807414e4660527bb4892e5b Mon Sep 17 00:00:00 2001 From: RikkaW Date: Thu, 6 May 2021 13:39:12 +0800 Subject: [PATCH] Show confirmation dialog if this is the only app to open the file --- app/src/main/AndroidManifest.xml | 8 +++++ .../java/app/rikka/savecopy/SaveActivity.java | 35 +++++++++++++++++-- .../java/app/rikka/savecopy/SaveService.java | 1 - app/src/main/res/values-v30/theme.xml | 4 --- app/src/main/res/values-zh-rCN/strings.xml | 3 +- app/src/main/res/values-zh-rTW/strings.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- app/src/main/res/values/theme.xml | 4 ++- 8 files changed, 49 insertions(+), 12 deletions(-) delete mode 100644 app/src/main/res/values-v30/theme.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05eb896..e3bbd20 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,14 @@ android:maxSdkVersion="29" tools:ignore="ScopedStorage" /> + + + + + + + + checkPermission()) + .setOnDismissListener(dialog -> finish()) + .show(); + return; + } + checkPermission(); + } + + private void checkPermission() { if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || (Build.VERSION.SDK_INT == 29 && Build.VERSION.PREVIEW_SDK_INT == 0))) { String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (checkSelfPermission(permissions[0]) != PackageManager.PERMISSION_GRANTED @@ -35,10 +52,11 @@ protected void onCreate(Bundle savedInstanceState) { return; } } - handleIntent(); + + startSave(); } - private void handleIntent() { + private void startSave() { String callingPackage = null; Uri referrer = getReferrer(); if (referrer != null) callingPackage = referrer.getAuthority(); @@ -62,7 +80,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis granted &= grantResult == PackageManager.PERMISSION_GRANTED; } if (granted) { - handleIntent(); + startSave(); } else { boolean isNight = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) > 0; int theme = isNight ? android.R.style.Theme_DeviceDefault_Dialog_Alert : android.R.style.Theme_DeviceDefault_Light_Dialog_Alert; @@ -81,4 +99,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } } } + + private boolean shouldShowConfirmation() { + try { + Intent intentForTest = new Intent(getIntent()); + intentForTest.setComponent(null); + intentForTest.setPackage(null); + return getPackageManager().queryIntentActivities(intentForTest, PackageManager.MATCH_DEFAULT_ONLY).size() <= 1; + } catch (Throwable e) { + return true; + } + } } diff --git a/app/src/main/java/app/rikka/savecopy/SaveService.java b/app/src/main/java/app/rikka/savecopy/SaveService.java index f92d4d6..a1ce003 100644 --- a/app/src/main/java/app/rikka/savecopy/SaveService.java +++ b/app/src/main/java/app/rikka/savecopy/SaveService.java @@ -73,7 +73,6 @@ public void onCreate() { }); mNotificationManager = getSystemService(NotificationManager.class); - //noinspection ConstantConditions onCreateNotificationChannel(mNotificationManager); startForeground(NOTIFICATION_ID_PROGRESS, onStartForeground()); diff --git a/app/src/main/res/values-v30/theme.xml b/app/src/main/res/values-v30/theme.xml deleted file mode 100644 index 055a45e..0000000 --- a/app/src/main/res/values-v30/theme.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file +