How to obtain MANAGE_EXTERNAL_STORAGE permission

17,415

Android 10 doesn't require "android.permission.MANAGE_EXTERNAL_STORAGE", android:requestLegacyExternalStorage="true" under application tag in manifest will work.

For android 11, try this

if (Environment.isExternalStorageManager()) {
    //todo when permission is granted
} else {
    //request for the permission
    Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
    Uri uri = Uri.fromParts("package", getPackageName(), null);
    intent.setData(uri);
    startActivity(intent);
}
Share:
17,415

Related videos on Youtube

Serhii K.
Author by

Serhii K.

Updated on July 14, 2022

Comments

  • Serhii K.
    Serhii K. almost 2 years

    I'm trying to get the MANAGE_EXTERNAL_STORAGE permission on my Android 10 (API 29) device.

    https://developer.android.com/training/data-storage/manage-all-files

    Manifest:

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    

    MainActivity:

    Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
    startActivity(intent);
    

    The result is:

    No Activity found to handle Intent { act=android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION }
    

    Okay, this behaviour is possible. The doc says:

    In some cases, a matching Activity may not exist, so ensure you safeguard against this.
    

    But how can I obtain that permission?

    • ianhanniballake
      ianhanniballake over 3 years
      That permission and the associated action only exist on API 30, none of that applies to an API 29 device. What are you trying to do?
    • blackapps
      blackapps over 3 years
  • nayan dhabarde
    nayan dhabarde about 3 years
    what if the user returns from settings without enabling it? Do you have the request code to handle that?
  • Nahid Hasan
    Nahid Hasan about 3 years
    Scoped storage enforcement Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.
  • irkoch
    irkoch over 2 years
    this should be the accepted answer, good job