Skip to content

Commit b5699a2

Browse files
committed
fixed SDK33 permission denied error.
1 parent c16ad71 commit b5699a2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

core/src/main/AndroidManifest.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
xmlns:tools="http://schemas.android.com/tools"
33
tools:ignore="ExtraText">
44

5-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
5+
<!-- Required only if your app targets Android 13. -->
6+
<!-- Declare one or more the following permissions only if your app needs
7+
to access data thats protected by them. -->
8+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
9+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
10+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
11+
12+
<!-- Required to maintain app compatibility. -->
13+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
14+
android:maxSdkVersion="32" />
715

816
/
917
</manifest>

core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.raphaelebner.roomdatabasebackup.core
22

3-
import android.Manifest.permission.READ_EXTERNAL_STORAGE
4-
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
3+
import android.Manifest.permission.*
54
import android.app.Activity
65
import android.content.Context
76
import android.content.Intent
@@ -369,7 +368,11 @@ class RoomBackup(var context: Context) : FragmentActivity() {
369368
}
370369
BACKUP_FILE_LOCATION_CUSTOM_DIALOG -> {
371370
backupFilename = filename
372-
permissionRequestLauncher.launch(arrayOf(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE))
371+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
372+
permissionRequestLauncher.launch(arrayOf(READ_MEDIA_IMAGES, READ_MEDIA_AUDIO, READ_MEDIA_VIDEO))
373+
} else {
374+
permissionRequestLauncher.launch(arrayOf(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE))
375+
}
373376
return
374377
}
375378
BACKUP_FILE_LOCATION_CUSTOM_FILE -> {
@@ -497,7 +500,11 @@ class RoomBackup(var context: Context) : FragmentActivity() {
497500
backupDirectory = File("$EXTERNAL_BACKUP_PATH/")
498501
}
499502
BACKUP_FILE_LOCATION_CUSTOM_DIALOG -> {
500-
permissionRequestLauncher.launch(arrayOf(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE))
503+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
504+
permissionRequestLauncher.launch(arrayOf(READ_MEDIA_IMAGES, READ_MEDIA_AUDIO, READ_MEDIA_VIDEO))
505+
} else {
506+
permissionRequestLauncher.launch(arrayOf(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE))
507+
}
501508
return
502509
}
503510
BACKUP_FILE_LOCATION_CUSTOM_FILE -> {

0 commit comments

Comments
 (0)