handle new storage permissions for API 33

- handle requesting READ_MEDIA_IMAGES and READ_MEDIA_VIDEO for Android 13+
- request WRITE_EXTERNAL_STORAGE for Android 12 and below
- set the permission WRITE_EXTERNAL_STORAGE to maxSdkVersion=32 in the AndroidManifest
This commit is contained in:
darthpaul 2022-09-29 00:49:16 +01:00
parent 1ea0664b7c
commit d9afde41ed
2 changed files with 22 additions and 2 deletions

View File

@ -19,7 +19,13 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission <uses-permission
android:name="android.permission.USE_FINGERPRINT" android:name="android.permission.USE_FINGERPRINT"
tools:node="remove" /> tools:node="remove" />

View File

@ -222,7 +222,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
private fun tryInitCamera() { private fun tryInitCamera() {
handlePermission(PERMISSION_CAMERA) { grantedCameraPermission -> handlePermission(PERMISSION_CAMERA) { grantedCameraPermission ->
if (grantedCameraPermission) { if (grantedCameraPermission) {
handlePermission(PERMISSION_WRITE_STORAGE) { grantedStoragePermission -> handleStoragePermission { grantedStoragePermission ->
if (grantedStoragePermission) { if (grantedStoragePermission) {
if (mIsInPhotoMode) { if (mIsInPhotoMode) {
initializeCamera() initializeCamera()
@ -249,6 +249,20 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
} }
} }
private fun handleStoragePermission(callback: (granted: Boolean) -> Unit) {
if (isTiramisuPlus()) {
handlePermission(PERMISSION_READ_MEDIA_IMAGES) { grantedReadImages ->
if (grantedReadImages) {
handlePermission(PERMISSION_READ_MEDIA_VIDEO) { grantedReadVideos ->
callback.invoke(grantedReadVideos)
}
}
}
} else {
handlePermission(PERMISSION_WRITE_STORAGE, callback)
}
}
private fun is3rdPartyIntent() = isVideoCaptureIntent() || isImageCaptureIntent() private fun is3rdPartyIntent() = isVideoCaptureIntent() || isImageCaptureIntent()
private fun isImageCaptureIntent(): Boolean = intent?.action == MediaStore.ACTION_IMAGE_CAPTURE || intent?.action == MediaStore.ACTION_IMAGE_CAPTURE_SECURE private fun isImageCaptureIntent(): Boolean = intent?.action == MediaStore.ACTION_IMAGE_CAPTURE || intent?.action == MediaStore.ACTION_IMAGE_CAPTURE_SECURE