forked from hardcoresushi/DroidFS
Fix storage permission requests
This commit is contained in:
parent
1e75e9a32f
commit
a726f7a7d0
@ -80,16 +80,6 @@ class SelectPathFragment: Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestManageAllFiles(): Boolean {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
if (!Environment.isExternalStorageManager()) {
|
|
||||||
startActivity(Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:"+requireContext().packageName)))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
originalRememberVolume = sharedPrefs.getBoolean(ConstValues.REMEMBER_VOLUME_KEY, true)
|
originalRememberVolume = sharedPrefs.getBoolean(ConstValues.REMEMBER_VOLUME_KEY, true)
|
||||||
@ -111,29 +101,33 @@ class SelectPathFragment: Fragment() {
|
|||||||
refreshStatus(binding.editVolumeName.text)
|
refreshStatus(binding.editVolumeName.text)
|
||||||
}
|
}
|
||||||
binding.buttonPickDirectory.setOnClickListener {
|
binding.buttonPickDirectory.setOnClickListener {
|
||||||
if (!requestManageAllFiles()) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Environment.isExternalStorageManager()) {
|
||||||
if (
|
|
||||||
ContextCompat.checkSelfPermission(
|
|
||||||
requireContext(),
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
|
||||||
) + ContextCompat.checkSelfPermission(
|
|
||||||
requireContext(),
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
|
||||||
) {
|
|
||||||
launchPickDirectory()
|
|
||||||
} else {
|
|
||||||
askStoragePermissions.launch(
|
|
||||||
arrayOf(
|
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
launchPickDirectory()
|
launchPickDirectory()
|
||||||
|
} else {
|
||||||
|
startActivity(Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:"+requireContext().packageName)))
|
||||||
}
|
}
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
if (
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
requireContext(),
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
|
) + ContextCompat.checkSelfPermission(
|
||||||
|
requireContext(),
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
launchPickDirectory()
|
||||||
|
} else {
|
||||||
|
askStoragePermissions.launch(
|
||||||
|
arrayOf(
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
launchPickDirectory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.editVolumeName.addTextChangedListener(object: TextWatcher {
|
binding.editVolumeName.addTextChangedListener(object: TextWatcher {
|
||||||
|
Loading…
Reference in New Issue
Block a user