From 9f152fc5adee304eb5df71963e5195a7ae5bcd6d Mon Sep 17 00:00:00 2001 From: Vishal Nehra Date: Tue, 31 Oct 2023 01:07:29 +0530 Subject: [PATCH] Add sdk33 checks --- .../superclasses/PermissionsActivity.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/ui/activities/superclasses/PermissionsActivity.java b/app/src/main/java/com/amaze/filemanager/ui/activities/superclasses/PermissionsActivity.java index 3ca97c186b..3a81b5ff2b 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/activities/superclasses/PermissionsActivity.java +++ b/app/src/main/java/com/amaze/filemanager/ui/activities/superclasses/PermissionsActivity.java @@ -33,6 +33,7 @@ import com.google.android.material.snackbar.Snackbar; import android.Manifest; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; @@ -91,9 +92,13 @@ public void onRequestPermissionsResult( public boolean checkStoragePermission() { // Verify that all required contact permissions have been granted. if (SDK_INT >= Build.VERSION_CODES.R) { - return ActivityCompat.checkSelfPermission( - this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) - == PackageManager.PERMISSION_GRANTED; + return (ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + == PackageManager.PERMISSION_GRANTED) + || (ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) + == PackageManager.PERMISSION_GRANTED) + || Environment.isExternalStorageManager(); } else { return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; @@ -266,6 +271,16 @@ private void requestAllFilesAccessPermission( new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) .setData(Uri.parse("package:" + getPackageName())); startActivity(intent); + } catch (ActivityNotFoundException anf) { + // fallback + try { + Intent intent = + new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) + .setData(Uri.parse("package:$packageName")); + startActivity(intent); + } catch (Exception e) { + AppConfig.toast(this, getString(R.string.grantfailed)); + } } catch (Exception e) { Log.e(TAG, "Failed to initial activity to grant all files access", e); AppConfig.toast(this, getString(R.string.grantfailed));