From b2cda03e3af23035b7d71629703b8ebc89f14eec Mon Sep 17 00:00:00 2001 From: MajorTanya <39014446+MajorTanya@users.noreply.github.com> Date: Mon, 14 Sep 2026 22:20:09 +0200 Subject: [PATCH] Use modern OpenDocument for backup file selection (#3948) This might also fix the underlying problem of #3947. I don't have any nonstandard devices available, but this works fine in an A17 Pixel emulator & on my A14 Xiaomi device. Looks like the GetContent approach was merely carried over from older code without being updated to the more modern OpenDocument contract. --- .../settings/screen/SettingsDataScreen.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index 488cb08d9..ef5b6f95d 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -1,7 +1,6 @@ package eu.kanade.presentation.more.settings.screen import android.content.ActivityNotFoundException -import android.content.Context import android.content.Intent import android.net.Uri import androidx.activity.compose.ManagedActivityResultLauncher @@ -186,18 +185,22 @@ object SettingsDataScreen : SearchableSettings { val lastAutoBackup by backupPreferences.lastAutoBackupTimestamp.collectAsState() val chooseBackup = rememberLauncherForActivityResult( - object : ActivityResultContracts.GetContent() { - override fun createIntent(context: Context, input: String): Intent { - val intent = super.createIntent(context, input) - return Intent.createChooser(intent, context.stringResource(MR.strings.file_select_backup)) - } - }, + ActivityResultContracts.OpenDocument(), ) { if (it == null) { context.toast(MR.strings.file_null_uri_error) return@rememberLauncherForActivityResult } + try { + context.contentResolver.takePersistableUriPermission( + it, + Intent.FLAG_GRANT_READ_URI_PERMISSION, + ) + } catch (e: SecurityException) { + logcat(LogPriority.ERROR, e) + } + navigator.push(RestoreBackupScreen(it.toString())) } @@ -232,9 +235,7 @@ object SettingsDataScreen : SearchableSettings { if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) { context.toast(MR.strings.restore_miui_warning) } - - // no need to catch because it's wrapped with a chooser - chooseBackup.launch("*/*") + chooseBackup.launch(arrayOf("*/*")) } else { context.toast(MR.strings.restore_in_progress) }