Professional Documents
Culture Documents
Intent Filter
Intent Filter
There are three Intent characteristics you can filter on: the action, data, and categories.
For each of these characteristics you can provide multiple possible matching values
(via addAction(String),addDataType(String), addDataScheme(String), addData
SchemeSpecificPart(String, int),addDataAuthority(String,
String), addDataPath(String, int), and addCategory(String), respectively). For
actions, the field will not be tested if no values have been given (treating it as a
wildcard); if no data characteristics are specified, however, then the filter will only match
intents that contain no data.
The data characteristic is itself divided into three attributes: type, scheme, authority, and
path. Any that are specified must match the contents of the Intent. If you specify a
scheme but no type, only Intent that does not have a type (such as mailto:) will match; a
content: URI will never match because they always have a MIME type that is supplied
by their content provider. Specifying a type with no scheme has somewhat special
meaning: it will match either an Intent with no URI field, or an Intent with a content: or
file: URI. If you specify neither, then only an Intent with no data or type will match. To
specify an authority, you must also specify one or more schemes that it is associated
with. To specify a path, you also must specify both one or more authorities and one or
more schemes it is associated with.
Developer Guides
For information about how to create and resolve intents, read the Intents and Intent Filters developer
guide.
Filter Rules
A match is based on the following rules. Note that for an IntentFilter to match an Intent,
three conditions must hold: the action and category must match, and the data (both
the data type and data scheme+authority+path if specified) must match
(see match(ContentResolver, Intent, boolean, String) for more details on how
the data fields match).
Action matches if any of the given values match the Intent action; if the filter specifies
no actions, then it will only match Intents that do not contain an action.
Data Type matches if any of the given values match the Intent type. The Intent type is
determined by calling resolveType(ContentResolver). A wildcard can be used for
the MIME sub-type, in both the Intent and IntentFilter, so that the type "audio/*" will
match "audio/mpeg", "audio/aiff", "audio/*", etc. Note that MIME type matching here
is case sensitive, unlike formal RFC MIME types! You should thus always use lower
case letters for your MIME types.
Data Scheme matches if any of the given values match the Intent data's scheme. The
Intent scheme is determined by calling getData() and getScheme() on that URI. Note
that scheme matching here is case sensitive, unlike formal RFC schemes! You should
thus always use lower case letters for your schemes.
Data Scheme Specific Part matches if any of the given values match the Intent's data
scheme specific part andone of the data schemes in the filter has matched the
Intent, or no scheme specific parts were supplied in the filter. The Intent scheme
specific part is determined by calling getData() and getSchemeSpecificPart() on
that URI. Note that scheme specific part matching is case sensitive.
Data Authority matches if any of the given values match the Intent's data
authority and one of the data schemes in the filter has matched the Intent, or no
authories were supplied in the filter. The Intent authority is determined by
calling getData() and getAuthority() on that URI. Note that authority matching here
is case sensitive, unlike formal RFC host names! You should thus always use lower
case letters for your authority.
Data Path matches if any of the given values match the Intent's data path and both a
scheme and authority in the filter has matched against the Intent, or no paths were
supplied in the filter. The Intent authority is determined by
calling getData() and getPath() on that URI.
Categories match if all of the categories in the Intent match categories given in the
filter. Extra categories in the filter that are not in the Intent will not cause the match to
fail. Note that unlike the action, an IntentFilter with no categories will only match an
Intent that does not have any categories.
Summary
Nested classes
class IntentFilter.AuthorityEntry
class IntentFilter.MalformedMimeTypeException
This exception is thrown when a given MIME type does not have a valid syntax.
Constants
int MATCH_ADJUSTMENT_MASK
The part of a match constant that applies a quality adjustment to the basic category of match.
int MATCH_ADJUSTMENT_NORMAL
Quality adjustment applied to the category of match that signifies the default, base value; higher numbers
quality while lower numbers reduce it.
int MATCH_CATEGORY_EMPTY
int MATCH_CATEGORY_HOST
The filter matched an intent with the same data URI scheme and authority host.
int MATCH_CATEGORY_MASK
The part of a match constant that describes the category of match that occurred.
int MATCH_CATEGORY_PATH
The filter matched an intent with the same data URI scheme, authority, and path.
int MATCH_CATEGORY_PORT
The filter matched an intent with the same data URI scheme and authority host and port.
int MATCH_CATEGORY_SCHEME
The filter matched an intent with the same data URI scheme.
int MATCH_CATEGORY_SCHEME_SPECIFIC_PART
The filter matched an intent with the same data URI scheme and scheme specific part.
int MATCH_CATEGORY_TYPE
The filter matched an intent with the same data MIME type.
int NO_MATCH_ACTION
int NO_MATCH_CATEGORY
The filter didn't match because it required one or more categories that were not in the Intent.
int NO_MATCH_DATA
int NO_MATCH_TYPE
int SYSTEM_HIGH_PRIORITY
The filter setPriority(int) value at which system high-priority receivers are placed; that is, receivers
execute before application code.
int SYSTEM_LOW_PRIORITY
The filter setPriority(int) value at which system low-priority receivers are placed; that is, receivers th
execute after application code.
Inherited constants
From interface android.os.Parcelable
Fields
Public constructors
IntentFilter()
IntentFilter(String action)
IntentFilter(String action, String
dataType)
IntentFilter(IntentFilter o)
Public methods
final Iterator<String> actionsIterator()
finalIterator<IntentFilter.Authorit authoritiesIterator()
yEntry>
Return an iterator over the filter's data authorities.
final Iterator<String> categoriesIterator()
static IntentFilter create(String action, String dataType)
void dump(Printer du, String prefix)
Is the given action included in the filter? Note that if the filter doe
include any actions, false will always be returned.
final boolean hasCategory(String category)
Is the given data authority included in the filter? Note that if the fi
not include any authorities, false will always be returned.
Is the given data path included in the filter? Note that if the filter d
include any paths, false will always be returned.
Is the given data scheme included in the filter? Note that if the fil
include any scheme, false will always be returned.
Is the given data scheme specific part included in the filter? Note
filter does not include any scheme specific parts, false will alway
returned.
Is the given data type included in the filter? Note that if the filter d
include any type, false will always be returned.
Match this filter against an Intent's data (type, scheme and path)
finalIterator<PatternMatcher> pathsIterator()
void readFromXml(XmlPullParser parser)
finalIterator<PatternMatcher> schemeSpecificPartsIterator()
final Iterator<String> schemesIterator()
final Iterator<String> typesIterator()
void writeToXml(XmlSerializer serializer)
Inherited methods
From class java.lang.Object
From interface android.os.Parcelable
Constants
MATCH_ADJUSTMENT_MASK
added in API level 1
int MATCH_ADJUSTMENT_MASK
The part of a match constant that applies a quality adjustment to the basic category of
match. The value MATCH_ADJUSTMENT_NORMAL is no adjustment; higher numbers than
that improve the quality, while lower numbers reduce it.
MATCH_ADJUSTMENT_NORMAL
added in API level 1
int MATCH_ADJUSTMENT_NORMAL
Quality adjustment applied to the category of match that signifies the default, base
value; higher numbers improve the quality while lower numbers reduce it.
MATCH_CATEGORY_EMPTY
added in API level 1
int MATCH_CATEGORY_EMPTY
int MATCH_CATEGORY_HOST
The filter matched an intent with the same data URI scheme and authority host.
MATCH_CATEGORY_MASK
added in API level 1
int MATCH_CATEGORY_MASK
The part of a match constant that describes the category of match that occurred. May
be
either MATCH_CATEGORY_EMPTY, MATCH_CATEGORY_SCHEME, MATCH_CATEGORY_SCHEME_
SPECIFIC_PART,MATCH_CATEGORY_HOST, MATCH_CATEGORY_PORT, MATCH_CATEGORY_PA
TH, or MATCH_CATEGORY_TYPE. Higher values indicate a better match.
MATCH_CATEGORY_PATH
added in API level 1
int MATCH_CATEGORY_PATH
The filter matched an intent with the same data URI scheme, authority, and path.
MATCH_CATEGORY_PORT
added in API level 1
int MATCH_CATEGORY_PORT
The filter matched an intent with the same data URI scheme and authority host and
port.
MATCH_CATEGORY_SCHEME
added in API level 1
int MATCH_CATEGORY_SCHEME
The filter matched an intent with the same data URI scheme.
MATCH_CATEGORY_SCHEME_SPECIFIC_PART
added in API level 19
int MATCH_CATEGORY_SCHEME_SPECIFIC_PART
The filter matched an intent with the same data URI scheme and scheme specific part.
MATCH_CATEGORY_TYPE
added in API level 1
int MATCH_CATEGORY_TYPE
The filter matched an intent with the same data MIME type.
NO_MATCH_ACTION
added in API level 1
int NO_MATCH_ACTION
NO_MATCH_CATEGORY
added in API level 1
int NO_MATCH_CATEGORY
The filter didn't match because it required one or more categories that were not in the
Intent.
NO_MATCH_DATA
added in API level 1
int NO_MATCH_DATA
NO_MATCH_TYPE
added in API level 1
int NO_MATCH_TYPE
int SYSTEM_HIGH_PRIORITY
See also:
setPriority(int)
SYSTEM_LOW_PRIORITY
added in API level 1
int SYSTEM_LOW_PRIORITY
See also:
setPriority(int)
Fields
CREATOR
added in API level 1
Creator<IntentFilter> CREATOR
Public constructors
IntentFilter
added in API level 1
IntentFilter ()
IntentFilter
added in API level 1
New IntentFilter that matches a single action with no data. If no data characteristics are
subsequently specified, then the filter will only match intents that contain no data.
Parameters
IntentFilter
added in API level 1
String dataType)
Parameters
Throws
IntentFilter.MalformedMimeTypeException
IntentFilter
added in API level 1
IntentFilter (IntentFilter o)
Parameters
Public methods
actionsIterator
added in API level 1
Iterator<String> actionsIterator ()
Return an iterator over the filter's actions. If there are no actions, returns null.
Returns
Iterator<String>
addAction
added in API level 1
Add a new Intent action to match against. If any actions are included in the filter, then
an Intent's action must be one of those values for it to match. If no actions are included,
the Intent action is ignored.
Parameters
addCategory
added in API level 1
Add a new Intent category to match against. The semantics of categories is the
opposite of actions -- an Intent includes the categories that it requires, all of which must
be included in the filter in order to match. In other words, adding a category to the filter
has no impact on matching unless that category is specified in the intent.
Parameters
String port)
Add a new Intent data authority to match against. The filter must include one or more
schemes (via addDataScheme(String)) for the authority to be considered. If any
authorities are included in the filter, then an Intent's data must match one of them. If no
authorities are included, then only the scheme must match.
Note: host name in the Android framework is case-sensitive, unlike formal RFC host
names. As a result, you should always write your host names with lower case letters,
and any host names you receive from outside of Android should be converted to lower
case before supplying them here.
Parameters
hos String: The host part of the authority to match. May start with a single '*' to wildcard the front of the host n
t
por String: Optional port part of the authority to match. If null, any port is allowed.
t
See also:
addDataPath
added in API level 1
int type)
Add a new Intent data path to match against. The filter must include one or more
schemes (via addDataScheme(String)) and one or more authorities
(via addDataAuthority(String, String)) for the path to be considered. If any paths
are included in the filter, then an Intent's data must match one of them. If no paths are
included, then only the scheme/authority must match.
The path given here can either be a literal that must directly match or match against a
prefix, or it can be a simple globbing pattern. If the latter, you can use '*' anywhere in
the pattern to match zero or more instances of the previous character, '.' as a wildcard
to match any character, and '\' to escape the next character.
Parameters
pat String: Either a raw string that must exactly match the file path, or a simple pattern, depending on type.
h
See also:
addDataScheme
added in API level 1
Add a new Intent data scheme to match against. If any schemes are included in the
filter, then an Intent's data must be either one of these schemes or a matching data
type. If no schemes are included, then an Intent will match only if it includes no data.
Note: scheme matching in the Android framework is case-sensitive, unlike formal RFC
schemes. As a result, you should always write your schemes with lower case letters,
and any schemes you receive from outside of Android should be converted to lower
case before supplying them here.
Parameters
addDataSchemeSpecificPart
added in API level 19
int type)
Add a new Intent data "scheme specific part" to match against. The filter must include
one or more schemes (via addDataScheme(String)) for the scheme specific part to be
considered. If any scheme specific parts are included in the filter, then an Intent's data
must match one of them. If no scheme specific parts are included, then only the scheme
must match.
The "scheme specific part" that this matches against is the string returned
by Uri.getSchemeSpecificPart. For Uris that contain a path, this kind of matching is
not generally of interest, since addDataAuthority(String,
String) and addDataPath(String, int) can provide a better mechanism for
matching them. However, for Uris that do not contain a path, the authority and path are
empty, so this is the only way to match against the non-scheme part.
Parameters
ssp String: Either a raw string that must exactly match the scheme specific part path, or a simple pattern, dep
on type.
See also:
addDataType
added in API level 1
Add a new Intent data type to match against. If any types are included in the filter, then
an Intent's data must be either one of these types or a matching scheme. If no data
types are included, then an Intent will only match if it specifies no data.
Note: MIME type matching in the Android framework is case-sensitive, unlike formal
RFC MIME types. As a result, you should always write your MIME types with lower
case letters, and any MIME types you receive from outside of Android should be
converted to lower case before supplying them here.
Parameters
Throws
IntentFilter.MalformedMimeTypeException
See also:
authoritiesIterator
added in API level 1
Iterator<IntentFilter.AuthorityEntry> authoritiesIterator ()
Returns
Iterator<IntentFilter.AuthorityEntry>
categoriesIterator
added in API level 1
Iterator<String> categoriesIterator ()
Returns
countActions
added in API level 1
int countActions ()
Returns
int
countCategories
added in API level 1
int countCategories ()
Returns
int
countDataAuthorities
added in API level 1
int countDataAuthorities ()
Returns
int
countDataPaths
added in API level 1
int countDataPaths ()
Returns
int
countDataSchemeSpecificParts
added in API level 19
int countDataSchemeSpecificParts ()
Returns
int
countDataSchemes
added in API level 1
int countDataSchemes ()
Returns
int
countDataTypes
added in API level 1
int countDataTypes ()
Returns
int
create
added in API level 1
String dataType)
Create a new IntentFilter instance with a specified action and MIME type, where you
know the MIME type is correctly formatted. This catches
the IntentFilter.MalformedMimeTypeException exception that the constructor can
call and turns it into a runtime exception.
Parameters
Returns
See also:
IntentFilter(String, String)
describeContents
added in API level 1
int describeContents ()
Describe the kinds of special objects contained in this Parcelable instance's marshaled
representation. For example, if the object will include a file descriptor in the output
of writeToParcel(Parcel, int), the return value of this method must include
the CONTENTS_FILE_DESCRIPTOR bit.
Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
dump
added in API level 1
String prefix)
Parameters
du Printer
prefix String
getAction
added in API level 1
Parameters
index int
Returns
String
getCategory
added in API level 1
Parameters
index int
Returns
String
getDataAuthority
added in API level 1
Parameters
index int
Returns
IntentFilter.AuthorityEntry
getDataPath
added in API level 1
Parameters
index int
Returns
PatternMatcher
getDataScheme
added in API level 1
Parameters
index int
Returns
String
getDataSchemeSpecificPart
added in API level 19
Parameters
index int
Returns
PatternMatcher
getDataType
added in API level 1
Parameters
index int
Returns
String
getPriority
added in API level 1
int getPriority ()
Returns
See also:
setPriority(int)
hasAction
added in API level 1
Is the given action included in the filter? Note that if the filter does not include any
actions, false will always be returned.
Parameters
action String: The action to look for.
Returns
hasCategory
added in API level 1
Parameters
Returns
hasDataAuthority
added in API level 1
Is the given data authority included in the filter? Note that if the filter does not include
any authorities, false will always be returned.
Parameters
Returns
boolean Returns true if the data string matches an authority listed in the filter.
hasDataPath
added in API level 1
Is the given data path included in the filter? Note that if the filter does not include any
paths, false will always be returned.
Parameters
data String: The data path to look for. This is without the scheme prefix.
Returns
boolean True if the data string matches a path listed in the filter.
hasDataScheme
added in API level 1
Is the given data scheme included in the filter? Note that if the filter does not include any
scheme, false will always be returned.
Parameters
Returns
Is the given data scheme specific part included in the filter? Note that if the filter does
not include any scheme specific parts, false will always be returned.
Parameters
data String: The scheme specific part that is being looked for.
Returns
boolean Returns true if the data string matches a scheme specific part listed in the filter.
hasDataType
added in API level 1
Is the given data type included in the filter? Note that if the filter does not include any
type, false will always be returned.
Parameters
Returns
match
added in API level 1
int match (String action,
String type,
String scheme,
Uri data,
Set<String> categories,
String logTag)
Test whether this filter matches the given intent data. A match is only successful if the
actions and categories in the Intent match against the filter, as described
in IntentFilter; in that case, the match result returned will be as
per matchData(String, String, Uri).
Parameters
Returns
See also:
match
added in API level 1
Intent intent,
boolean resolve,
String logTag)
Parameters
resolver ContentResolver
resolve boolean: If true, the intent's type will be resolved by calling Intent.resolveType(); otherwise a simple m
against Intent.type will be performed.
Returns
See also:
Match this filter against an Intent's action. If the filter does not specify any actions, the
match will always fail.
Parameters
Returns
matchCategories
added in API level 1
Match this filter against an Intent's categories. Each category in the Intent must be
specified by the filter; if any are not in the filter, the match fails.
Parameters
Returns
String If all categories match (success), null; else the name of the first category that didn't match.
matchData
added in API level 1
int matchData (String type,
String scheme,
Uri data)
Match this filter against an Intent's data (type, scheme and path). If the filter does not
specify any types and does not specify any schemes/paths, the match will only succeed
if the intent does not also specify a type or data. If the filter does not specify any
schemes, it will implicitly match intents with no scheme, or the schemes "content:" or
"file:" (basically performing a MIME-type only match). If the filter does not specify any
MIME types, the Intent also must not specify a MIME type.
Be aware that to match against an authority, you must also specify a base scheme the
authority is in. To match against a data path, both a scheme and authority must be
specified. If the filter does not specify any types or schemes that it matches against, it is
considered to be empty (any authority or data path given is ignored, as if it were empty
as well).
Note: MIME type, Uri scheme, and host name matching in the Android framework is
case-sensitive, unlike the formal RFC definitions. As a result, you should always write
these elements with lower case letters, and normalize any MIME types or Uris you
receive from outside of Android to ensure these elements are lower case before
supplying them here.
Parameters
type String: The desired data type to look for, as returned by Intent.resolveType().
scheme String: The desired data scheme to look for, as returned by Intent.getScheme().
data Uri: The full data string to match against, as supplied in Intent.data.
Returns
See also:
Match this intent filter against the given Intent data. This ignores the data scheme --
unlike matchData(String, String, Uri), the authority will match regardless of
whether there is a matching scheme.
Parameters
Returns
pathsIterator
added in API level 1
Iterator<PatternMatcher> pathsIterator ()
Returns
Iterator<PatternMatcher
>
readFromXml
added in API level 1
parser XmlPullParser
Throws
XmlPullParserException
IOException
schemeSpecificPartsIterator
added in API level 19
Iterator<PatternMatcher> schemeSpecificPartsIterator ()
Returns
Iterator<PatternMatcher
>
schemesIterator
added in API level 1
Iterator<String> schemesIterator ()
Returns
Iterator<String>
setPriority
added in API level 1
Modify priority of this filter. This only affects receiver filters. The priority of activity filters
are set in XML and cannot be changed programatically. The default priority is 0. Positive
values will be before the default, lower values will be after it. Applications should use a
value that is larger than SYSTEM_LOW_PRIORITY and smaller
than SYSTEM_HIGH_PRIORITY .
Parameters
See also:
getPriority()
SYSTEM_LOW_PRIORITY
SYSTEM_HIGH_PRIORITY
typesIterator
added in API level 1
Iterator<String> typesIterator ()
Returns
Iterator<String>
writeToParcel
added in API level 1
void writeToParcel (Parcel dest,
int flags)
Parameters
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_
writeToXml
added in API level 1
Parameters
serializer XmlSerializer
Throws
IOException