1page.title=Sharing Files
2page.tags=FileProvider,share,ContentProvider
3
4trainingnavtop=true
5startpage=true
6
7
8@jd:body
9
10<div id="tb-wrapper">
11<div id="tb">
12
13<h2>Dependencies and prerequisites</h2>
14<ul>
15  <li>Android 1.6 (API Level 4) or higher</li>
16  <li>Familiarity with file operations such as opening, reading, and writing files</li>
17</ul>
18
19<h2>You should also read</h2>
20<ul>
21    <li><a href="{@docRoot}guide/topics/data/data-storage.html">Storage Options</a></li>
22    <li><a href="{@docRoot}training/basics/data-storage/files.html">Saving Files</a>
23    <li><a href="{@docRoot}training/sharing/index.html">Sharing Simple Data</a></li>
24</ul>
25
26</div>
27</div>
28
29<p>
30    Apps often have a need to offer one or more of their files to another app. For example, an image
31    gallery may want to offer files to image editors, or a file management app may want to allow
32    users to copy and paste files between areas in external storage. One way a sending app can
33    share a file is to respond to a request from the receiving app.
34</p>
35<p>
36    In all cases, the only secure way to offer a file from your app to another app is to send the
37    receiving app the file's content URI and grant temporary access permissions to that URI.
38    Content URIs with temporary URI access permissions are secure because they apply only to the
39    app that receives the URI, and they expire automatically. The Android
40    {@link android.support.v4.content.FileProvider} component provides the method
41    {@link android.support.v4.content.FileProvider#getUriForFile getUriForFile()} for
42    generating a file's content URI.
43</p>
44<p>
45    If you want to share small amounts of text or numeric data between apps, you should send an
46    {@link android.content.Intent} that contains the data. To learn how to send simple data with an
47    {@link android.content.Intent}, see the training class
48    <a href="{@docRoot}training/sharing/index.html">Sharing Simple Data</a>.
49</p>
50<p>
51    This class explains how to securely share files from your app to another app using content URIs
52    generated by the Android {@link android.support.v4.content.FileProvider} component and
53    temporary permissions that you grant to the receiving app for the content URI.
54</p>
55<h2>Lessons</h2>
56<dl>
57    <dt><b><a href="setup-sharing.html">Setting Up File Sharing</a></b></dt>
58    <dd>
59        Learn how to set up your app to share files.
60    </dd>
61    <dt><b><a href="share-file.html">Sharing a File</a></b></dt>
62    <dd>
63        Learn how to offer a file to another app by generating a content URI for the file,
64        granting access permissions to the URI, and sending the URI to the app.
65    </dd>
66    <dt><b><a href="request-file.html">Requesting a Shared File</a></b></dt>
67    <dd>
68        Learn how to request a file shared by another app, receive the content URI for the file,
69        and use the content URI to open the file.
70    </dd>
71    <dt>
72        <b><a href="retrieve-info.html">Retrieving File Information</a></b>
73    </dt>
74    <dd>
75        Learn how an app can use a content URI generated by a
76        {@link android.support.v4.content.FileProvider} to retrieve file information including
77        MIME type and file size.
78    </dd>
79</dl>
80
81
82