Sharing files
Stay organized with collections
Save and categorize content based on your preferences.
Apps often have a need to offer one or more of their files to another app. For example, an image
gallery may want to offer files to image editors, or a file management app may want to allow
users to copy and paste files between areas in external storage. One way a sending app can
share a file is to respond to a request from the receiving app.
In all cases, the only secure way to offer a file from your app to another app is to send the
receiving app the file's content URI and grant temporary access permissions to that URI.
Content URIs with temporary URI access permissions are secure because they apply only to the
app that receives the URI, and they expire automatically. The Android
FileProvider
component provides the method
getUriForFile()
for
generating a file's content URI.
If you want to share small amounts of text or numeric data between apps, you should send an
Intent
that contains the data. To learn how to send simple data with an
Intent
, see the training class
Sharing simple data.
This class explains how to securely share files from your app to another app using content URIs
generated by the Android FileProvider
component and
temporary permissions that you grant to the receiving app for the content URI.
Lessons
- Setting up file sharing
-
Learn how to set up your app to share files.
- Sharing a file
-
Learn how to offer a file to another app by generating a content URI for the file,
granting access permissions to the URI, and sending the URI to the app.
- Requesting a shared file
-
Learn how to request a file shared by another app, receive the content URI for the file,
and use the content URI to open the file.
-
Retrieving file information
-
Learn how an app can use a content URI generated by a
FileProvider
to retrieve file information including
MIME type and file size.
For additional related information, refer to:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Sharing files\n\nApps often have a need to offer one or more of their files to another app. For example, an image\ngallery may want to offer files to image editors, or a file management app may want to allow\nusers to copy and paste files between areas in external storage. One way a sending app can\nshare a file is to respond to a request from the receiving app.\n\n\nIn all cases, the only secure way to offer a file from your app to another app is to send the\nreceiving app the file's content URI and grant temporary access permissions to that URI.\nContent URIs with temporary URI access permissions are secure because they apply only to the\napp that receives the URI, and they expire automatically. The Android\n[FileProvider](/reference/androidx/core/content/FileProvider) component provides the method\n[getUriForFile()](/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context, java.lang.String, java.io.File)) for\ngenerating a file's content URI.\n\n\nIf you want to share small amounts of text or numeric data between apps, you should send an\n[Intent](/reference/android/content/Intent) that contains the data. To learn how to send simple data with an\n[Intent](/reference/android/content/Intent), see the training class\n[Sharing simple data](/training/sharing).\n\n\nThis class explains how to securely share files from your app to another app using content URIs\ngenerated by the Android [FileProvider](/reference/androidx/core/content/FileProvider) component and\ntemporary permissions that you grant to the receiving app for the content URI.\n\nLessons\n-------\n\n**[Setting up file sharing](/training/secure-file-sharing/setup-sharing)**\n:\n Learn how to set up your app to share files.\n\n**[Sharing a file](/training/secure-file-sharing/share-file)**\n:\n Learn how to offer a file to another app by generating a content URI for the file,\n granting access permissions to the URI, and sending the URI to the app.\n\n**[Requesting a shared file](/training/secure-file-sharing/request-file)**\n:\n Learn how to request a file shared by another app, receive the content URI for the file,\n and use the content URI to open the file.\n\n\n**[Retrieving file information](/training/secure-file-sharing/retrieve-info)**\n:\n Learn how an app can use a content URI generated by a\n [FileProvider](/reference/androidx/core/content/FileProvider) to retrieve file information including\n MIME type and file size.\n\nFor additional related information, refer to:\n\n- [Storage Options](/guide/topics/data/data-storage)\n- [Saving Files](/training/basics/data-storage/files)\n- [Sharing Simple Data](/training/sharing)"]]