How to access permission READ_INTERNAL_STORAGE and WRITE_INTERNAL_STORAGE file (pdf docs)in android SDK 33

Viewed 47

In Android 13 version or SDK 33 How to access all files in android devices and also give permission of Allow management of all files, I have try requestLegacyExternalStorage, defaultToDeviceProtectedStorage, requestLegacyExternalStorage="true" and READ_INTERNAL_STORAGE, WRITE_INTERNAL_STORAGE permission but not working.

In android 11 and 12 is working fine but In android 13 it's not working.

if (ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("application/pdf");
            startActivityForResult(intent, SELECT_FILE_REQUEST);
        } else {
            ActivityCompat.requestPermissions(requireActivity(), new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
        }
1 Answers

MANAGE_EXTERNAL_STORAGE permission is particularly dangerous permission. It must be provide manually. Try this:

    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",applicationContext.packageName))
    startActivity(intent)

Note: The Google Play store has a policy that restricts the use of the MANAGE_EXTERNAL_STORAGE permission if the app is intended to be published to the store.

Related