当应用以 Android 11 或更高版本为目标平台并声明了 MANAGE_EXTERNAL_STORAGE 权限时,Android Studio 会显示图 1 中所示的 lint 警告。此警告会提醒您:“Google Play 商店的一项政策限制了对该权限的使用”。
图 1. Android Studio 中的 Lint 警告,提醒开发者有关 MANAGE_EXTERNAL_STORAGE 权限的 Google Play 政策。
仅当您的应用无法有效利用更有利于保护隐私的 API(如存储访问框架或 Media Store API)时,您才能请求 MANAGE_EXTERNAL_STORAGE 权限。您的应用对该权限的使用必须在允许的使用情形范围内,并且必须与应用的核心功能直接相关。如果您的应用包含与以下任一项类似的用例,可能会请求 MANAGE_EXTERNAL_STORAGE 权限:
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Manage all files on a storage device\n\nThe majority of apps that require shared storage access can follow the best\npractices for [sharing media\nfiles](/training/data-storage/use-cases#share-media-all) and [sharing non-media\nfiles](/training/data-storage/use-cases#sharing-non-media-files). However, some\napps have a core use case that requires broad access to files on a device, but\ncan't access them efficiently using the privacy-friendly storage best practices.\nAndroid provides a special app access called *all-files access* for these\nsituations.\n\nFor example, an anti-virus app's primary use case might require regular scanning\nof many files across different directories. If this scanning requires repeated\nuser interactions to select directories using the system file picker, it\nprovides a poor user experience. Other use cases---such as file manager apps,\nbackup and restore apps, and document management apps---require similar\nconsiderations.\n\nRequest all-files access\n------------------------\n\nAn app can request all-files access from the user by doing the following:\n\n1. Declare the [`MANAGE_EXTERNAL_STORAGE`](/reference/android/Manifest.permission#MANAGE_EXTERNAL_STORAGE) permission in the manifest.\n2. Use the [`ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION`](/reference/android/provider/Settings#ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) intent action to direct users to a system settings page where they can enable the following option for your app: **Allow access to manage all files**.\n\nTo determine whether your app has been granted the `MANAGE_EXTERNAL_STORAGE`\npermission, call\n[`Environment.isExternalStorageManager()`](/reference/android/os/Environment#isExternalStorageManager()).\n\nOperations permitted by MANAGE_EXTERNAL_STORAGE\n-----------------------------------------------\n\nThe `MANAGE_EXTERNAL_STORAGE` permission grants the following:\n\n- Read and write access to all files within [shared\n storage](/training/data-storage/shared).\n\n | **Note:** The `/sdcard/Android/media` directory is part of shared storage.\n- Access to the contents of the\n [`MediaStore.Files`](/reference/android/provider/MediaStore.Files) table.\n\n- Access to the root directory of both the USB on-the-go (OTG) drive and the SD\n card.\n\n- Write access to all internal storage directories except\n `/Android/data/`, `/sdcard/Android`, and most subdirectories of\n `/sdcard/Android`. This write access includes [direct file\n path](/training/data-storage/shared/media#direct-file-paths) access.\n\n Apps that are granted this permission still can't access the [app-specific\n directories](/training/data-storage/app-specific) that belong to other apps,\n because these directories appear as subdirectories of `Android/data/` on a\n storage volume.\n\nWhen an app has the `MANAGE_EXTERNAL_STORAGE` permission, it can access these\nadditional files and directories using either the\n[`MediaStore`](/reference/android/provider/MediaStore) API or [direct file\npaths](/training/data-storage/shared/media#direct-file-paths). When you use the\n[Storage Access Framework](/training/data-storage/shared/documents-files),\nhowever, you can only access a file or directory if you can do so without\nhaving the `MANAGE_EXTERNAL_STORAGE` permission.\n\nInvoke another app's storage management activity\n------------------------------------------------\n\nOn Android 12 (API level 31) and higher, apps that have both the\n[`MANAGE_EXTERNAL_STORAGE`](/reference/android/Manifest.permission#MANAGE_EXTERNAL_STORAGE)\npermission and the\n[`QUERY_ALL_PACKAGES`](/reference/android/Manifest.permission#QUERY_ALL_PACKAGES)\npermission---such as file management apps---can use the\n[`getManageSpaceActivityIntent()`](/reference/android/os/storage/StorageManager#getManageSpaceActivityIntent(java.lang.String,%20int))\nto send users to another app's [custom space management\nactivity](/training/data-storage/app-specific#create-storage-management-activity).\n\nThe `getManageSpaceActivityIntent()` method takes in a package name and a\nrequest code, and it returns one of the following:\n\n- A [`PendingIntent`](/reference/android/app/PendingIntent), if the app with the specified package name has defined a custom \"manage space\" activity. The file management app that called the `getManageSpaceActivityIntent()` method can then invoke the returned intent to send users to the custom activity.\n- `null`, if the app with the specified package name doesn't define a \"manage space\" activity.\n\nEnable MANAGE_EXTERNAL_STORAGE for testing\n------------------------------------------\n\nTo explore how the `MANAGE_EXTERNAL_STORAGE` permission affects your app, you\ncan enable the permission for testing. To do so, run the following\ncommand on the machine that's connected to your test device: \n\n```\nadb shell appops set --uid PACKAGE_NAME MANAGE_EXTERNAL_STORAGE allow\n```\n\nGoogle Play notice\n------------------\n\nThis section provides a notice for developers who publish apps on Google Play.\n\nTo limit broad access to shared storage, the Google Play store has [updated its\npolicy](https://support.google.com/googleplay/android-developer/answer/10467955)\nto evaluate apps that target Android 11 (API level 30) or higher and request\nall-files access through the `MANAGE_EXTERNAL_STORAGE` permission. This policy\nis in effect as of May 2021.\n\nWhen your app targets Android 11 or higher and it declares the\n`MANAGE_EXTERNAL_STORAGE` permission, Android Studio shows the lint warning that\nappears in figure 1. This warning reminds you that the Google Play store has a\npolicy that limits usage of the permission.\n**Figure 1.** Lint warning in Android Studio that reminds developers about the Google Play policy regarding the `MANAGE_EXTERNAL_STORAGE` permission.\n\nRequest the `MANAGE_EXTERNAL_STORAGE` permission only when your app\ncan't effectively make use of the more privacy-friendly APIs, such as the [Storage\nAccess Framework](/training/data-storage/shared/documents-files) or the [Media\nStore API](/training/data-storage/shared/media). Your app's usage\nof the permission must fall within permitted uses and must be directly tied to\nthe core functionality of the app. If your app includes a use case\nsimilar to any of the following, it's likely that it can request the\n`MANAGE_EXTERNAL_STORAGE` permission:\n\n- File managers\n- Backup and restore apps\n- Anti-virus apps\n- Document management apps\n- On-device file search\n- Disk and file encryption\n- [Device-to-device data migration](/guide/topics/data/testingbackup#TestingTransfer)"]]