- syntax:
<data android:scheme="string" android:host="string" android:port="string" android:path="string" android:pathPattern="string" android:pathPrefix="string" android:pathSuffix="string" android:pathAdvancedPattern="string" android:mimeType="string" />
- contained in:
<intent-filter>
- description:
- Adds a data specification to an intent filter. The specification can
be just a data type (the
mimeType
attribute), just a URI, or both a data type and a URI. A URI is specified by separate attributes for each of its parts:<scheme>://<host>:<port>[<path>|<pathPrefix>|<pathPattern>|<pathAdvancedPattern>|<pathSuffix>]
These attributes that specify the URL format are optional, but also mutually dependent:
- If a
scheme
is not specified for the intent filter, all the other URI attributes are ignored. - If a
host
is not specified for the filter, theport
attribute and all the path attributes are ignored.
All the
<data>
elements contained within the same<intent-filter>
element contribute to the same filter. So, for example, the following filter specification,<intent-filter . . . > <data android:scheme="something" android:host="project.example.com" /> . . . </intent-filter>
is equivalent to this one:
<intent-filter . . . > <data android:scheme="something" /> <data android:host="project.example.com" /> . . . </intent-filter>
You can place any number of
<data>
elements inside an<intent-filter>
to give it multiple data options. None of its attributes have default values.Information on how intent filters work, including the rules for how Intent objects are matched against filters, can be found in another document, Intents and Intent Filters. See also the Intent Filters section in the manifest file overview.
- If a
- attributes:
android:scheme
- The scheme part of a URI. This is the minimal essential attribute for
specifying a URI; at least one
scheme
attribute must be set for the filter, or none of the other URI attributes are meaningful.A scheme is specified without the trailing colon (for example,
http
, rather thanhttp:
).If the filter has a data type set (the
mimeType
attribute) but no scheme, thecontent:
andfile:
schemes are assumed.Note: Scheme matching in the Android framework is case-sensitive, unlike the RFC. As a result, you should always specify schemes using lowercase letters.
android:host
-
The host part of a URI authority. This attribute is meaningless
unless a
scheme
attribute is also specified for the filter. To match multiple subdomains, use an asterisk (*
) to match zero or more characters in the host. For example, the host*.google.com
matcheswww.google.com
,.google.com
, anddeveloper.google.com
.The asterisk must be the first character of the host attribute. For example, the host
google.co.*
is invalid because the asterisk wildcard is not the first character.Note: host name matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always specify host names using lowercase letters.
android:port
- The port part of a URI authority. This attribute is meaningful only
if the
scheme
andhost
attributes are also specified for the filter. android:path
android:pathPrefix
android:pathSuffix
android:pathPattern
android:pathAdvancedPattern
- The path part of a URI which must begin with a /.
The
path
attribute specifies a complete path that is matched against the complete path in an Intent object. ThepathPrefix
attribute specifies a partial path that is matched against only the initial part of the path in the Intent object. ThepathSuffix
attribute is matched exactly against the ending part of the path in the Intent object, and this attribute is not required to begin with the '/' character. ThepathPattern
attribute specifies a complete path that is matched against the complete path in the Intent object, but it can contain the following wildcards:- An asterisk ('
*
') matches a sequence of 0 to many occurrences of the immediately preceding character. - A period followed by an asterisk ("
.*
") matches any sequence of 0 to many characters.
The
pathAdvancedPattern
attribute specifies a complete path, which is matched against the complete path of the Intent object, and supports the following regex-like patterns:-
A period ('
.
') matches any character. -
A set ('
[...]
') matches ranges of characters. For example ,[0-5]
matches a single digit from 0 through 5 but not 6 through 9. Likewise,[a-zA-Z]
would match any letter regardless of case. Sets also support the not^
modifier. -
The star ('
*
') modifier matches the preceeding pattern 0 or more times. -
The plus ('
+
') modifier matches the preceeding pattern 1 or more times. -
The range ('
{...}
') modifier can be used to specify the number of times a pattern may match.
pathAdvancedPattern
matcher is a simple evaluation implementation in which matching is done against the pattern in real time with no backtracking support.Because '
\
' is used as an escape character when the string is read from XML (before it is parsed as a pattern), you will need to double-escape: For example, a literal '*
' would be written as "\\*
" and a literal '\
' would be written as "\\\\
". This is basically the same as what you would need to write if constructing the string in Java code.For more information on these five types of patterns, see the descriptions of
PATTERN_LITERAL
,PATTERN_PREFIX
,PATTERN_SIMPLE_GLOB
,PATTERN_SUFFIX
, andPATTERN_ADVANCED_GLOB
in thePatternMatcher
class.These attributes are meaningful only if the
scheme
andhost
attributes are also specified for the filter.pathSuffix
andpathAdvancePattern
were introduced in API Level 31. - An asterisk ('
android:mimeType
- A MIME media type, such as
image/jpeg
oraudio/mpeg4-generic
. The subtype can be the asterisk wildcard (*
) to indicate that any subtype matches.It's common for an intent filter to declare a
<data>
that includes only theandroid:mimeType
attribute.Note: MIME type matching in the Android framework is case-sensitive, unlike formal RFC MIME types. As a result, you should always specify MIME types using lowercase letters.
- introduced in:
- API Level 1
- see also:
<action>
<category>
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 2023-03-08 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]