can't find permission MANAGE_EXTERNAL_STORAGE and not find Settings.ACTION_MANAGE_ALL_FILES_ACCESS android studio android studio version is 2020.3.1 gradle version 4.1.3 compilerVersion 30 targetVersion 30
CodePudding user response:
Call this method before taking any file from storage
private fun requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try {
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.addCategory("android.intent.category.DEFAULT")
intent.data = Uri.parse(String.format("package:%s", requireContext().packageName))
startActivityForResult(intent, 1000)
} catch (e: Exception) {
val intent = Intent()
intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION
startActivityForResult(intent, 1000)
}
} else {
ActivityCompat.requestPermissions(
requireActivity(),
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
1000 )
}
}
Then in onActivityResult you can check request code if it is 1000 then get Uri from data intent
CodePudding user response:
Declare the MANAGE_EXTERNAL_STORAGE permission in the manifest.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>