Skip to content

Commit

Permalink
Storage permissions dependent on Android SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
budowski committed Sep 6, 2023
1 parent 7b013ce commit d8f5fdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions iNaturalist/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand All @@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.location.gps" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,14 +1283,20 @@ 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) {
requestPermissions(activity, new String[] { Manifest.permission.RECORD_AUDIO }, cb);
}

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();
Expand Down Expand Up @@ -1332,6 +1338,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
} else {
cb.onPermissionDenied();
}

break;
}
}
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d8f5fdf

Please sign in to comment.