feat: 从SD卡兼容所有文件管理权限
This commit is contained in:
@ -3,9 +3,14 @@ package com.gh.vspace.installexternalgames
|
||||
import android.Manifest
|
||||
import android.app.Dialog
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.gh.common.util.DialogUtils
|
||||
@ -37,6 +42,9 @@ class InstallExternalGameFragment : ToolbarFragment(), OnItemClickListener {
|
||||
|
||||
private var uninstallDisposable: Disposable? = null
|
||||
|
||||
|
||||
private var shouldScan = false
|
||||
|
||||
override fun getLayoutId() = 0
|
||||
|
||||
override fun getInflatedLayout() =
|
||||
@ -74,9 +82,26 @@ class InstallExternalGameFragment : ToolbarFragment(), OnItemClickListener {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
shouldScan = true
|
||||
AlertDialog.Builder(requireContext()).setMessage("请在设置页面允许光环助手")
|
||||
.setNegativeButton("去") { dialog, which ->
|
||||
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}.show()
|
||||
} else {
|
||||
mViewModel.scanPaths()
|
||||
}
|
||||
} else {
|
||||
requestStoragePermission()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun requestStoragePermission() {
|
||||
when {
|
||||
ContextCompat.checkSelfPermission(
|
||||
@ -96,6 +121,12 @@ class InstallExternalGameFragment : ToolbarFragment(), OnItemClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (shouldScan) {
|
||||
mViewModel.scanPaths()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
dialog = DialogUtils.showWaitDialog(requireContext(), "")
|
||||
|
||||
Reference in New Issue
Block a user