| page.title=Sharing Files |
| page.tags=FileProvider,share,ContentProvider |
| |
| trainingnavtop=true |
| startpage=true |
| |
| |
| @jd:body |
| |
| <div id="tb-wrapper"> |
| <div id="tb"> |
| |
| <h2>Dependencies and prerequisites</h2> |
| <ul> |
| <li>Android 1.6 (API Level 4) or higher</li> |
| <li>Familiarity with file operations such as opening, reading, and writing files</li> |
| </ul> |
| |
| <h2>You should also read</h2> |
| <ul> |
| <li><a href="{@docRoot}guide/topics/data/data-storage.html">Storage Options</a></li> |
| <li><a href="{@docRoot}training/basics/data-storage/files.html">Saving Files</a> |
| <li><a href="{@docRoot}training/sharing/index.html">Sharing Simple Data</a></li> |
| </ul> |
| |
| </div> |
| </div> |
| |
| <p> |
| 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. |
| </p> |
| <p> |
| 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 |
| {@link android.support.v4.content.FileProvider} component provides the method |
| {@link android.support.v4.content.FileProvider#getUriForFile getUriForFile()} for |
| generating a file's content URI. |
| </p> |
| <p> |
| If you want to share small amounts of text or numeric data between apps, you should send an |
| {@link android.content.Intent} that contains the data. To learn how to send simple data with an |
| {@link android.content.Intent}, see the training class |
| <a href="{@docRoot}training/sharing/index.html">Sharing Simple Data</a>. |
| </p> |
| <p> |
| This class explains how to securely share files from your app to another app using content URIs |
| generated by the Android {@link android.support.v4.content.FileProvider} component and |
| temporary permissions that you grant to the receiving app for the content URI. |
| </p> |
| <h2>Lessons</h2> |
| <dl> |
| <dt><b><a href="setup-sharing.html">Setting Up File Sharing</a></b></dt> |
| <dd> |
| Learn how to set up your app to share files. |
| </dd> |
| <dt><b><a href="share-file.html">Sharing a File</a></b></dt> |
| <dd> |
| 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. |
| </dd> |
| <dt><b><a href="request-file.html">Requesting a Shared File</a></b></dt> |
| <dd> |
| 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. |
| </dd> |
| <dt> |
| <b><a href="retrieve-info.html">Retrieving File Information</a></b> |
| </dt> |
| <dd> |
| Learn how an app can use a content URI generated by a |
| {@link android.support.v4.content.FileProvider} to retrieve file information including |
| MIME type and file size. |
| </dd> |
| </dl> |
| |
| |