From 83d1da4947e5df2ec58d1e4253076ae04c703640 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 5 Apr 2021 10:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/cache/CacheActivity.kt | 5 ----- .../app/ui/book/local/ImportBookActivity.kt | 5 ----- .../legado/app/ui/config/BackupConfigFragment.kt | 16 ---------------- .../legado/app/ui/document/FilePickerActivity.kt | 6 ++++++ 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 23b4289f3..fbdae644b 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.cache -import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -42,10 +41,6 @@ class CacheActivity : VMBaseActivity() private val exportDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) startExport(uri.toString()) } else { diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 185ba4f23..8dfa25975 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.local -import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle @@ -46,10 +45,6 @@ class ImportBookActivity : VMBaseActivity uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.importBookPath = uri.toString() initRootDoc() } else { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 8359259d4..1b6c8ba45 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.config -import android.content.Intent import android.content.SharedPreferences import android.net.Uri import android.os.Bundle @@ -40,11 +39,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val selectBackupPath = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() } else { AppConfig.backupPath = uri.path @@ -53,11 +47,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val backupDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() Coroutine.async { Backup.backup(appCtx, uri.toString()) @@ -78,11 +67,6 @@ class BackupConfigFragment : BasePreferenceFragment(), private val restoreDir = registerForActivityResult(FilePicker()) { uri -> uri ?: return@registerForActivityResult if (uri.isContentScheme()) { - appCtx.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) AppConfig.backupPath = uri.toString() Coroutine.async { Restore.restore(appCtx, uri.toString()) diff --git a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt b/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt index bcbf8dce7..3c83b3845 100644 --- a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt +++ b/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt @@ -23,6 +23,12 @@ class FilePickerActivity : private val selectDocTree = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { + if (it.isContentScheme()) { + contentResolver.takePersistableUriPermission( + it, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + } onResult(Intent().setData(it)) }