From f64d95d3a215c374579348495b53668d6c8dd4f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Jan 2023 22:01:11 +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 --- .../legado/app/lib/permission/PermissionActivity.kt | 11 ++++++++--- .../java/io/legado/app/lib/permission/Permissions.kt | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt b/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt index 6dc7757b0..e1c615320 100644 --- a/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt +++ b/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt @@ -47,9 +47,14 @@ class PermissionActivity : AppCompatActivity() { //所有文件所有文件的管理权限 Request.TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION -> try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - val settingIntent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) - settingIntent.data = Uri.parse("package:$packageName") - settingActivityResult.launch(settingIntent) + kotlin.runCatching { + val settingIntent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) + settingIntent.data = Uri.parse("package:$packageName") + settingActivityResult.launch(settingIntent) + }.onFailure { + val settingIntent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) + settingActivityResult.launch(settingIntent) + } } else { throw NoStackTraceException("no MANAGE_ALL_FILES_ACCESS_PERMISSION") } diff --git a/app/src/main/java/io/legado/app/lib/permission/Permissions.kt b/app/src/main/java/io/legado/app/lib/permission/Permissions.kt index b4d22b914..301cafc6f 100644 --- a/app/src/main/java/io/legado/app/lib/permission/Permissions.kt +++ b/app/src/main/java/io/legado/app/lib/permission/Permissions.kt @@ -1,5 +1,7 @@ package io.legado.app.lib.permission +import android.os.Build + @Suppress("unused") object Permissions { @@ -40,8 +42,11 @@ object Permissions { const val ACCESS_MEDIA_LOCATION = "android.permission.ACCESS_MEDIA_LOCATION" object Group { - val STORAGE = - arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, MANAGE_EXTERNAL_STORAGE) + val STORAGE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + arrayOf(READ_EXTERNAL_STORAGE, MANAGE_EXTERNAL_STORAGE) + } else { + arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) + } val CAMERA = arrayOf(Permissions.CAMERA)