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.
This commit is contained in:
MajorTanya
2026-09-14 22:20:09 +02:00
committed by GitHub
parent fdc2d40a1d
commit b2cda03e3a
@@ -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)
}