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:
parent
1ea0664b7c
commit
d9afde41ed
|
@ -19,7 +19,13 @@
|
|||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<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
|
||||
android:name="android.permission.USE_FINGERPRINT"
|
||||
tools:node="remove" />
|
||||
|
|
|
@ -222,7 +222,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
private fun tryInitCamera() {
|
||||
handlePermission(PERMISSION_CAMERA) { grantedCameraPermission ->
|
||||
if (grantedCameraPermission) {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) { grantedStoragePermission ->
|
||||
handleStoragePermission { grantedStoragePermission ->
|
||||
if (grantedStoragePermission) {
|
||||
if (mIsInPhotoMode) {
|
||||
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 isImageCaptureIntent(): Boolean = intent?.action == MediaStore.ACTION_IMAGE_CAPTURE || intent?.action == MediaStore.ACTION_IMAGE_CAPTURE_SECURE
|
||||
|
|
Loading…
Reference in New Issue