mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
4979cc66e1
commit
d567919fb1
@ -2,6 +2,7 @@ package io.legado.app.lib.permission
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
@ -34,15 +35,7 @@ class PermissionActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//跳转到设置界面
|
//跳转到设置界面
|
||||||
Request.TYPE_REQUEST_SETTING -> try {
|
Request.TYPE_REQUEST_SETTING -> openSettingsActivity()
|
||||||
val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
||||||
settingIntent.data = Uri.fromParts("package", packageName, null)
|
|
||||||
settingActivityResult.launch(settingIntent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
toastOnUi(R.string.tip_cannot_jump_setting_page)
|
|
||||||
RequestPlugins.sRequestCallback?.onError(e)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
//所有文件的管理权限
|
//所有文件的管理权限
|
||||||
Request.TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION -> try {
|
Request.TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION -> try {
|
||||||
if (Permissions.isManageExternalStorage()) {
|
if (Permissions.isManageExternalStorage()) {
|
||||||
@ -56,6 +49,30 @@ class PermissionActivity : AppCompatActivity() {
|
|||||||
RequestPlugins.sRequestCallback?.onError(e)
|
RequestPlugins.sRequestCallback?.onError(e)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
Request.TYPE_REQUEST_NOTIFICATIONS -> kotlin.runCatching {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
//这种方案适用于 API 26, 即8.0(含8.0)以上可以用
|
||||||
|
val intent = Intent()
|
||||||
|
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||||
|
intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
||||||
|
intent.putExtra(Settings.EXTRA_CHANNEL_ID, applicationInfo.uid)
|
||||||
|
settingActivityResult.launch(intent)
|
||||||
|
} else {
|
||||||
|
openSettingsActivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openSettingsActivity() {
|
||||||
|
try {
|
||||||
|
val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
settingIntent.data = Uri.fromParts("package", packageName, null)
|
||||||
|
settingActivityResult.launch(settingIntent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
toastOnUi(R.string.tip_cannot_jump_setting_page)
|
||||||
|
RequestPlugins.sRequestCallback?.onError(e)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,10 +73,11 @@ internal class Request : OnRequestPermissionsResultCallback {
|
|||||||
|
|
||||||
val deniedPermissions = deniedPermissions
|
val deniedPermissions = deniedPermissions
|
||||||
val rationale = this.rationale
|
val rationale = this.rationale
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
||||||
if (deniedPermissions == null) {
|
if (deniedPermissions == null) {
|
||||||
onPermissionsGranted()
|
onPermissionsGranted()
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
if (rationale != null) {
|
if (rationale != null) {
|
||||||
showSettingDialog(rationale) {
|
showSettingDialog(rationale) {
|
||||||
onPermissionsDenied(deniedPermissions)
|
onPermissionsDenied(deniedPermissions)
|
||||||
@ -84,9 +85,7 @@ internal class Request : OnRequestPermissionsResultCallback {
|
|||||||
} else {
|
} else {
|
||||||
onPermissionsDenied(deniedPermissions)
|
onPermissionsDenied(deniedPermissions)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (deniedPermissions != null) {
|
|
||||||
if (deniedPermissions.contains(Permissions.MANAGE_EXTERNAL_STORAGE)) {
|
if (deniedPermissions.contains(Permissions.MANAGE_EXTERNAL_STORAGE)) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (rationale != null) {
|
if (rationale != null) {
|
||||||
@ -104,9 +103,6 @@ internal class Request : OnRequestPermissionsResultCallback {
|
|||||||
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
|
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
onPermissionsGranted()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,5 +244,6 @@ internal class Request : OnRequestPermissionsResultCallback {
|
|||||||
const val TYPE_REQUEST_PERMISSION = 1
|
const val TYPE_REQUEST_PERMISSION = 1
|
||||||
const val TYPE_REQUEST_SETTING = 2
|
const val TYPE_REQUEST_SETTING = 2
|
||||||
const val TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION = 3
|
const val TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION = 3
|
||||||
|
const val TYPE_REQUEST_NOTIFICATIONS = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user