From d8f5fdf154594b77257a2114dbf222b57b14b0f5 Mon Sep 17 00:00:00 2001 From: Yaron Budowski Date: Wed, 6 Sep 2023 09:41:36 +0300 Subject: [PATCH] Storage permissions dependent on Android SDK version --- iNaturalist/src/main/AndroidManifest.xml | 5 +++-- .../inaturalist/android/INaturalistApp.java | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/iNaturalist/src/main/AndroidManifest.xml b/iNaturalist/src/main/AndroidManifest.xml index e47654d60..70845e825 100644 --- a/iNaturalist/src/main/AndroidManifest.xml +++ b/iNaturalist/src/main/AndroidManifest.xml @@ -3,8 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" package="org.inaturalist.android" android:installLocation="auto" - android:versionCode="584" - android:versionName="1.29.10"> + android:versionCode="585" + android:versionName="1.29.11"> @@ -19,6 +19,7 @@ + diff --git a/iNaturalist/src/main/java/org/inaturalist/android/INaturalistApp.java b/iNaturalist/src/main/java/org/inaturalist/android/INaturalistApp.java index 123358ab3..b3ebc87aa 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/INaturalistApp.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/INaturalistApp.java @@ -1283,7 +1283,11 @@ public void requestAccessMediaLocationPermission(Activity activity, OnRequestPer } public void requestExternalStoragePermission(Activity activity, OnRequestPermissionResult cb) { - requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, cb); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + requestPermissions(activity, new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_AUDIO}, cb); + } else { + requestPermissions(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, cb); + } } public void requestAudioRecordingPermission(Activity activity, OnRequestPermissionResult cb) { @@ -1291,6 +1295,8 @@ public void requestAudioRecordingPermission(Activity activity, OnRequestPermissi } private void requestPermissions(final Activity activity, final String[] permissions, OnRequestPermissionResult cb) { + mPermissionsCbByPermissionName.clear(); + for (String permission: permissions) { mPermissionsCbByPermissionName.put(permission, cb); mPrefs.edit().putBoolean(permission, true).commit(); @@ -1332,6 +1338,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } else { cb.onPermissionDenied(); } + + break; } } } @@ -1361,9 +1369,16 @@ public boolean isPermissionPermanentlyDenied(Activity activity, String permissio } public boolean isExternalStoragePermissionGranted() { - return ( - PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + return ( + PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_MEDIA_IMAGES) == PermissionChecker.PERMISSION_GRANTED && + PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_MEDIA_AUDIO) == PermissionChecker.PERMISSION_GRANTED + ); + } else { + return ( + PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED ); + } } public boolean isAudioRecordingPermissionGranted() {