當應用程式指定 Android 11 以上版本為目標,並宣告 MANAGE_EXTERNAL_STORAGE 權限時,Android Studio 會出現 Lint 警告 (如圖 1 所示)。這則警告是要提醒您,Google Play 商店的政策對該權限的使用情況設有限制。
圖 1 Android Studio 的 Lint 警告,提醒開發人員有關 MANAGE_EXTERNAL_STORAGE 權限的 Google Play 政策。
請僅在應用程式無法善用 Storage Access Framework 或 Media Store API 等較能保障隱私權的 API 時,才要求 MANAGE_EXTERNAL_STORAGE 權限。應用程式只能將這項權限用於與核心功能直接相關的許可用途。如果應用程式的用途與以下內容類似,就可能可以要求 MANAGE_EXTERNAL_STORAGE 權限:
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["The 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\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\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\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\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\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)"]]