Home | History | Annotate | Download | only in manifest
      1 page.title=<data>
      2 parent.title=The AndroidManifest.xml File
      3 parent.link=manifest-intro.html
      4 @jd:body
      5 
      6 <dl class="xml">
      7 <dt>syntax:</dt>
      8 <dd><pre class="stx">&lt;data android:<a href="#scheme">scheme</a>="<i>string</i>"
      9       android:<a href="#host">host</a>="<i>string</i>"
     10       android:<a href="#port">port</a>="<i>string</i>"
     11       android:<a href="#path">path</a>="<i>string</i>"
     12       android:<a href="#path">pathPattern</a>="<i>string</i>"
     13       android:<a href="#path">pathPrefix</a>="<i>string</i>"
     14       android:<a href="#mime">mimeType</a>="<i>string</i>" /&gt;</pre></dd>
     15 
     16 
     17 <dt>contained in:</dt>
     18 <dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code></dd>
     19 
     20 <dt>description:</dt>
     21 <dd itemprop="description">Adds a data specification to an intent filter.  The specification can
     22 be just a data type (the <code><a href="{@docRoot}guide/topics/manifest/data-element.html#mime">mimeType</a></code> attribute),
     23 just a URI, or both a data type and a URI.  A URI is specified by separate
     24 attributes for each of its parts:
     25 
     26 <p style="margin-left: 2em">
     27 {@code &lt;scheme>://&lt;host>:&lt;port>/[&lt;path>|&lt;pathPrefix>|&lt;pathPattern>]}</p>
     28 
     29 <p>
     30 These attributes that specify the URL format are optional, but also mutually dependent:
     31 <ul>
     32   <li>If a <code><a href="{@docRoot}guide/topics/manifest/data-element.html#scheme">scheme</a></code>
     33 is not specified for the intent filter, all the other URI attributes are ignored.</li>
     34   <li>If a <code><a href="{@docRoot}guide/topics/manifest/data-element.html#host">host</a></code>
     35 is not specified for the filter, the {@code port} attribute and all the path attributes are ignored.
     36 </ul>
     37 
     38 <p>
     39 All the {@code &lt;data&gt;} elements contained within the same
     40 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element contribute to
     41 the same filter.  So, for example, the following filter specification,
     42 </p>
     43 
     44 <pre>&lt;intent-filter . . . &gt;
     45     &lt;data android:scheme="something" android:host="project.example.com" /&gt;
     46     . . .
     47 &lt;/intent-filter&gt;</pre>
     48 
     49 <p>is equivalent to this one:</p>
     50 
     51 <pre>&lt;intent-filter . . . &gt;
     52     &lt;data android:scheme="something" /&gt
     53     &lt;data android:host="project.example.com" /&gt;
     54     . . .
     55 &lt;/intent-filter&gt;</pre>
     56 
     57 <p>
     58 You can place any number of {@code &lt;data&gt;} elements inside an
     59 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> to give it multiple data
     60 options.  None of its attributes have default values.
     61 </p>
     62 
     63 <p>
     64 Information on how intent filters work, including the rules for how Intent objects
     65 are matched against filters, can be found in another document,
     66 <a href="{@docRoot}guide/components/intents-filters.html">Intents and
     67 Intent Filters</a>.  See also the
     68 <a href="{@docRoot}guide/topics/manifest/manifest-intro.html#ifs">Intent Filters</a>
     69 section in the manifest file overview.
     70 </p></dd>
     71 
     72 <dt>attributes:</dt>
     73 <dd><dl class="attr">
     74 
     75 <dt><a name="scheme"></a>{@code android:scheme}</dt>
     76 <dd>The scheme part of a URI.  This is the minimal essential attribute for
     77 specifying a URI; at least one {@code scheme} attribute must be set
     78 for the filter, or none of the other URI attributes are meaningful.
     79 
     80 <p>
     81 A scheme is specified without the trailing colon (for example,
     82 {@code http}, rather than {@code http:}).
     83 </p>
     84 
     85 <p>
     86 If the filter has a data type set (the <code><a
     87 href="{@docRoot}guide/topics/manifest/data-element.html#mime">mimeType</a></code>
     88 attribute) but no scheme, the {@code content:} and {@code file:} schemes are
     89 assumed.
     90 </p>
     91 
     92 <p class="note"><strong>Note</strong>: Scheme matching in the Android framework is
     93 case-sensitive, unlike the RFC.  As a result, you should always specify schemes
     94 using lowercase letters.</p>
     95 </dd>
     96 
     97 <dt><a name="host"></a>{@code android:host}</dt>
     98 <dd>The host part of a URI authority.  This attribute is meaningless
     99 unless a <code><a href="{@docRoot}guide/topics/manifest/data-element.html#scheme">scheme</a></code> attribute is also
    100 specified for the filter.
    101 
    102 <p class="note"><strong>Note</strong>: host name matching in the Android framework is
    103 case-sensitive, unlike the formal RFC.  As a result, you should always specify
    104 host names using lowercase letters.</p>
    105 </dd>
    106 
    107 
    108 <dt><a name="port"></a>{@code android:port}</dt>
    109 <dd>The port part of a URI authority.  This attribute is meaningful only
    110 if the <code><a href="#scheme">scheme</a></code> and
    111 <code><a href="#host">host</a></code> attributes are also specified for
    112 the filter.</dd>
    113 
    114 
    115 <dt><a name="path"></a>{@code android:path}
    116 <br/>{@code android:pathPrefix}
    117 <br/>{@code android:pathPattern}</dt>
    118 <dd>The path part of a URI.  The {@code path} attribute specifies a complete
    119 path that is matched against the complete path in an Intent object.  The
    120 {@code pathPrefix} attribute specifies a partial path that is matched against
    121 only the initial part of the path in the Intent object.  The {@code pathPattern}
    122 attribute specifies a complete path that is matched against the complete path
    123 in the Intent object, but it can contain the following wildcards:
    124 
    125 <ul>
    126 <li>An asterisk ('{@code *}') matches a sequence of 0 to many occurrences of
    127 the immediately preceding character.</li>
    128 
    129 <li>A period followed by an asterisk ("{@code .*}") matches any sequence of
    130 0 to many characters.</li>
    131 </ul>
    132 
    133 <p>
    134 Because '{@code \}' is used as an escape character when the string is read
    135 from XML (before it is parsed as a pattern), you will need to double-escape:
    136 For example, a literal '{@code *}' would be written as "{@code \\*}" and a
    137 literal '{@code \}' would be written as "{@code \\\\}".  This is basically
    138 the same as what you would need to write if constructing the string in Java code.
    139 </p>
    140 
    141 <p>
    142 For more information on these three types of patterns, see the descriptions of
    143 {@link android.os.PatternMatcher#PATTERN_LITERAL},
    144 {@link android.os.PatternMatcher#PATTERN_PREFIX}, and
    145 {@link android.os.PatternMatcher#PATTERN_SIMPLE_GLOB} in the
    146 {@link android.os.PatternMatcher} class.
    147 </p>
    148 
    149 <p>These attributes are meaningful only if the
    150 <code><a href="#scheme">scheme</a></code> and <code><a href="#host">host</a></code>
    151 attributes are also specified for the filter.
    152 </p></dd>
    153 
    154 <dt><a name="mime"></a>{@code android:mimeType}</dt>
    155 <dd>A MIME media type, such as {@code image/jpeg} or {@code audio/mpeg4-generic}.
    156 The subtype can be the asterisk wildcard ({@code *}) to indicate that any
    157 subtype matches.
    158 
    159 <p>It's common for an intent filter to declare a {@code &lt;data>} that includes
    160 only the {@code android:mimeType} attribute.</p>
    161 
    162 
    163 <p class="note"><strong>Note</strong>: MIME type matching in the Android framework is
    164 case-sensitive, unlike formal RFC MIME types.  As a result, you should always
    165 specify MIME types using lowercase letters.</p>
    166 </dd>
    167 
    168 </dl></dd>
    169 
    170 <!-- ##api level indication## -->
    171 <dt>introduced in:</dt>
    172 <dd>API Level 1</dd>
    173 
    174 <dt>see also:</dt>
    175 <dd><code><a href="{@docRoot}guide/topics/manifest/action-element.html">&lt;action&gt;</a></code>
    176 <br/><code><a href="{@docRoot}guide/topics/manifest/category-element.html">&lt;category&gt;</a></code></dd>
    177 
    178 </dl>
    179