Share file in Android 11 programmatically

Android 11 Limitation

Since Android 11, application data folder is invisible to 3rd party apps according to the storage permission change. You can no longer list files directly:

/storage/emulated/0/Android/data/[app_package]

Since QuickEdit 1.8.5, it supports to read the contents under data folder on Android 11, but needs some additional steps to grant permission to data folder.

Edit Files In Data Folder By QuickEdit

Please upgrade QuickEdit to version 1.8.5 and above, then you can use following way to grant QuickEdit read/write permission to data folder:

  • Navigate to Data Folder

    Using QuickEdit built-in file explorer to locate the data folder under internal storage, the path is similar as: /storage/emulated/0/Android/data

  • Grant Permission to Data Folder

    In latest QuickEdit version, a permission grant dialog will show up, it will point to the data folder, and please click "use this folder" to grant the permission.

    Share file in Android 11 programmatically
  • Access Data Folder as Normal

    After the grant access success, you can access data folder as normal.

Edit Files In Data Folder By QuickEdit (Legacy)

If you are using QuickEdit old version before 1.7.9, or previous solution not work for you, please try following guide.

Currently system level file management app can view and edit files under data folder on Android 11. You can use system built-in file manager to open the files and assign QuickEdit to edit the file.

Following is the steps how to do this:

  • Find System File Manager

    Please go to Android system settings, find storage section, click it. From the storage page, find "Files" item, and click it. If there are multiple file managers to open it, please make sure to choose "Open with Files" to open it, which is the system file manager app.

    Please see following screenshot for the steps:

    Share file in Android 11 programmatically
  • Open Data File By QuickEdit

    From the files app, please navigate to Android data folder, navigate to the app and file that you want to edit, and click "Floating Action Button with Edit Icon". From the popup app list, choose QuickEdit to edit the file.

    Please see following screenshot for the steps:

    Share file in Android 11 programmatically
  • Edit and Save Data File using QuickEdit

    Now you can edit and save the data file as other local files. If there is permission error popup when you saving your modifications, please double confirm that you choose "edit file with" option instead of "open file with" option in the previous step. Only "edit file with" option can give QuickEdit write permission.

Google Play restricts the use of high risk or sensitive permissions, including a special app access called All files access. This is only applicable to apps that target Android 11 (API level 30) and declare the MANAGE_EXTERNAL_STORAGE permission, which is added in Android 11. Also, this policy does not impact the usage of the READ_EXTERNAL_STORAGE permission. 

If your app does not require access to the MANAGE_EXTERNAL_STORAGE permission, you must remove it from your app's manifest in order to successfully publish your app. Details on policy-compliant alternative implementations are also enumerated below.

If your app meets the policy requirements for acceptable use or is eligible for an exception, you will be required to declare this and any other high risk permissions using the Declaration Form in Play Console.

Apps that fail to meet policy requirements or do not submit a Declaration Form may be removed from Google Play.

When should you request the All files access permission?

You should only access the All files access permission when your app cannot effectively make use of the more privacy-friendly best practices, such as the Storage Access Framework or the Media Store API. 

Additionally, the app’s usage of the permission must fall within permitted uses, and must be directly tied to the core functionality of the app. Core functionality is defined as the main purpose of the app. Without this core functionality, the app is "broken" or rendered unusable. The core functionality, as well as any core features that comprise this core functionality, must all be prominently documented and promoted in the app's description. 

Collapse All Expand All

Permitted uses of the All files access permission

For apps requesting access to the All files access permission, intended and permitted use includes file managers, backup and restore apps, anti-virus apps, and document management apps.

Apps granted access to this permission may not extend its use to undisclosed or invalid purposes.

Use

Eligible permission*

File management

App’s core purpose involves the access, editing, and management (including maintenance) of files and folders outside of its app-specific storage space

MANAGE_EXTERNAL_STORAGE

Backup and restore apps

App must have a need to automatically access multiple directories outside of its app-specific storage space for the purpose of backup and restore

Anti-virus apps

App’s core purpose is to scan the device and provide anti-virus security features to the device user

Document management apps

Apps that must locate, access, and edit compatible file types outside of its app-specific or shared storage

App must justify in their Console declaration why the solutions documented in the Access app-specific files or Storage Access Framework documentation are not sufficient for their purpose

Search (On Device)

App’s core purpose is to search through files and folders across the device’s external storage

Disk/Folder Encryption and Locking

App’s core purpose is to encrypt files and folders

Device Migration/Phone transfer

App’s core purpose is to help the user migrate to a new device


* Subject to Google Play review and approval.

Exceptions

Google Play may provide a temporary exception to apps that do not qualify as permitted use designated above, when:

  • The use of the permission enables the app’s core functionality.
  • There is currently no alternative method to provide the core functionality, or the use of the privacy-friendly alternatives (for example, MediaStore API or Storage Access Framework) has a substantially detrimental impact on the critical features of the app that are tied to the core functionality.
  • The impact on user privacy is mitigated by security and privacy best practices.

The developer must justify in their Console declaration why the Storage Access Framework or MediaStore API is not sufficient for their app’s purpose.

Note: Apps for carrier and OEM services, and private apps published under the Managed Google Play distribution platform may request permissions access for the above use cases, in addition to critical services that require access.

Invalid uses

In some cases, apps may wish to access sensitive user data for purposes where a safer and more secure alternative exists, or where risk of data exposure doesn't warrant access. 

Below is a list of common use cases that won't be permitted to request the MANAGE_EXTERNAL_STORAGE permission 

  • Media Files access (see Alternatives below)
  • Any File selection activity where the user manually selects individual files (see Alternatives below)

Note: This list is not exhaustive. For in-depth guidance, please refer to the All Files Access documentation and Scoped storage best practices guidance for developers.

Alternatives to common uses

Use

Alternatives

Access of Media Files

With the MediaStore API, apps can contribute and access media that’s available on an external storage volume without the need for the access All files permission.

User selects files for importing/transferring/processing

Developers should consider using Storage Access Framework as the privacy-friendly option for accessing files in shared storage, such as using the Storage Access Framework.

Important: If you change how your app uses these restricted permissions, you must submit the form again with updated and accurate information. Deceptive and undeclared uses of these permissions may result in a suspension of your app and/or termination of your developer account.

Was this helpful?

How can we improve it?

How do I share a file in Android programmatically?

Sharing a file.
On this page..
Receive file requests..
Create a file selection Activity. Define the file selection Activity in code..
Respond to a file selection..
Grant permissions for the file..
Share the file with the requesting app..

Why does Android 11 have restrictions file manager?

To protect user privacy, on devices that run Android 11 or higher, the system further restricts your app's access to other apps' private directories.

How do I access data files on Android 11?

Please go to Android system settings, find storage section, click it. From the storage page, find "Files" item, and click it. If there are multiple file managers to open it, please make sure to choose "Open with Files" to open it, which is the system file manager app.

How do I use scoped storage in Android 11?

Scoped storage is the default behavior in Android 10 and 11. Special access permission is introduced in Android 11. Once the app has been whitelisted on Google Play, the user can be asked for special permission. The Media Store in Android 11 has been upgraded.