FileDocCategorySizeDatePackage
IntentFilter.javaAPI DocAndroid 1.5 API54216Wed May 06 22:41:54 BST 2009android.content

IntentFilter

public class IntentFilter extends Object implements android.os.Parcelable
Structured description of Intent values to be matched. An IntentFilter can match against actions, categories, and data (either via its type, scheme, and/or path) in an Intent. It also includes a "priority" value which is used to order multiple matching filters.

IntentFilter objects are often created in XML as part of a package's {@link android.R.styleable#AndroidManifest AndroidManifest.xml} file, using {@link android.R.styleable#AndroidManifestIntentFilter intent-filter} tags.

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 {@link #addAction}, {@link #addDataType}, {@link #addDataScheme} {@link #addDataAuthority}, {@link #addDataPath}, and {@link #addCategory}, 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.

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.

Action matches if any of the given values match the Intent action, or if no actions were specified in the filter.

Data Type matches if any of the given values match the Intent type. The Intent type is determined by calling {@link Intent#resolveType}. 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 {@link Intent#getData} and {@link android.net.Uri#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 Authority matches if any of the given values match the Intent's data authority and one of the data scheme's in the filter has matched the Intent, or no authories were supplied in the filter. The Intent authority is determined by calling {@link Intent#getData} and {@link android.net.Uri#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 {@link Intent#getData} and {@link android.net.Uri#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.

Fields Summary
private static final String
SGLOB_STR
private static final String
PREFIX_STR
private static final String
LITERAL_STR
private static final String
PATH_STR
private static final String
PORT_STR
private static final String
HOST_STR
private static final String
AUTH_STR
private static final String
SCHEME_STR
private static final String
TYPE_STR
private static final String
CAT_STR
private static final String
NAME_STR
private static final String
ACTION_STR
public static final int
SYSTEM_HIGH_PRIORITY
The filter {@link #setPriority} value at which system high-priority receivers are placed; that is, receivers that should execute before application code. Applications should never use filters with this or higher priorities.
public static final int
SYSTEM_LOW_PRIORITY
The filter {@link #setPriority} value at which system low-priority receivers are placed; that is, receivers that should execute after application code. Applications should never use filters with this or lower priorities.
public static final int
MATCH_CATEGORY_MASK
The part of a match constant that describes the category of match that occurred. May be either {@link #MATCH_CATEGORY_EMPTY}, {@link #MATCH_CATEGORY_SCHEME}, {@link #MATCH_CATEGORY_HOST}, {@link #MATCH_CATEGORY_PORT}, {@link #MATCH_CATEGORY_PATH}, or {@link #MATCH_CATEGORY_TYPE}. Higher values indicate a better match.
public static final int
MATCH_ADJUSTMENT_MASK
The part of a match constant that applies a quality adjustment to the basic category of match. The value {@link #MATCH_ADJUSTMENT_NORMAL} is no adjustment; higher numbers than that improve the quality, while lower numbers reduce it.
public static final 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.
public static final int
MATCH_CATEGORY_EMPTY
The filter matched an intent that had no data specified.
public static final int
MATCH_CATEGORY_SCHEME
The filter matched an intent with the same data URI scheme.
public static final int
MATCH_CATEGORY_HOST
The filter matched an intent with the same data URI scheme and authority host.
public static final int
MATCH_CATEGORY_PORT
The filter matched an intent with the same data URI scheme and authority host and port.
public static final int
MATCH_CATEGORY_PATH
The filter matched an intent with the same data URI scheme, authority, and path.
public static final int
MATCH_CATEGORY_TYPE
The filter matched an intent with the same data MIME type.
public static final int
NO_MATCH_TYPE
The filter didn't match due to different MIME types.
public static final int
NO_MATCH_DATA
The filter didn't match due to different data URIs.
public static final int
NO_MATCH_ACTION
The filter didn't match due to different actions.
public static final int
NO_MATCH_CATEGORY
The filter didn't match because it required one or more categories that were not in the Intent.
private int
mPriority
private final ArrayList
mActions
private ArrayList
mCategories
private ArrayList
mDataSchemes
private ArrayList
mDataAuthorities
private ArrayList
mDataPaths
private ArrayList
mDataTypes
private boolean
mHasPartialTypes
public static final Parcelable.Creator
CREATOR
Constructors Summary
public IntentFilter()
New empty IntentFilter.

        mPriority = 0;
        mActions = new ArrayList<String>();
    
private IntentFilter(android.os.Parcel source)

        mActions = new ArrayList<String>();
        source.readStringList(mActions);
        if (source.readInt() != 0) {
            mCategories = new ArrayList<String>();
            source.readStringList(mCategories);
        }
        if (source.readInt() != 0) {
            mDataSchemes = new ArrayList<String>();
            source.readStringList(mDataSchemes);
        }
        if (source.readInt() != 0) {
            mDataTypes = new ArrayList<String>();
            source.readStringList(mDataTypes);
        }
        int N = source.readInt();
        if (N > 0) {
            mDataAuthorities = new ArrayList<AuthorityEntry>();
            for (int i=0; i<N; i++) {
                mDataAuthorities.add(new AuthorityEntry(source));
            }
        }
        N = source.readInt();
        if (N > 0) {
            mDataPaths = new ArrayList<PatternMatcher>();
            for (int i=0; i<N; i++) {
                mDataPaths.add(new PatternMatcher(source));
            }
        }
        mPriority = source.readInt();
        mHasPartialTypes = source.readInt() > 0;
    
public IntentFilter(String action)
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.

param
action The action to match, i.e. Intent.ACTION_MAIN.

        mPriority = 0;
        mActions = new ArrayList<String>();
        addAction(action);
    
public IntentFilter(String action, String dataType)
New IntentFilter that matches a single action and data type.

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.

Throws {@link MalformedMimeTypeException} if the given MIME type is not syntactically correct.

param
action The action to match, i.e. Intent.ACTION_VIEW.
param
dataType The type to match, i.e. "vnd.android.cursor.dir/person".

        mPriority = 0;
        mActions = new ArrayList<String>();
        addDataType(dataType);
    
public IntentFilter(IntentFilter o)
New IntentFilter containing a copy of an existing filter.

param
o The original filter to copy.

        mPriority = o.mPriority;
        mActions = new ArrayList<String>(o.mActions);
        if (o.mCategories != null) {
            mCategories = new ArrayList<String>(o.mCategories);
        }
        if (o.mDataTypes != null) {
            mDataTypes = new ArrayList<String>(o.mDataTypes);
        }
        if (o.mDataSchemes != null) {
            mDataSchemes = new ArrayList<String>(o.mDataSchemes);
        }
        if (o.mDataAuthorities != null) {
            mDataAuthorities = new ArrayList<AuthorityEntry>(o.mDataAuthorities);
        }
        if (o.mDataPaths != null) {
            mDataPaths = new ArrayList<PatternMatcher>(o.mDataPaths);
        }
        mHasPartialTypes = o.mHasPartialTypes;
    
Methods Summary
public final java.util.IteratoractionsIterator()
Return an iterator over the filter's actions. If there are no actions, returns null.

        return mActions != null ? mActions.iterator() : null;
    
public final voidaddAction(java.lang.String action)
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.

param
action Name of the action to match, i.e. Intent.ACTION_VIEW.

        if (!mActions.contains(action)) {
            mActions.add(action.intern());
        }
    
public final voidaddCategory(java.lang.String category)
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.

param
category Name of category to match, i.e. Intent.CATEGORY_EMBED.

        if (mCategories == null) mCategories = new ArrayList<String>();
        if (!mCategories.contains(category)) {
            mCategories.add(category.intern());
        }
    
public final voidaddDataAuthority(java.lang.String host, java.lang.String port)
Add a new Intent data authority to match against. The filter must include one or more schemes (via {@link #addDataScheme}) 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.

param
host The host part of the authority to match. May start with a single '*' to wildcard the front of the host name.
param
port Optional port part of the authority to match. If null, any port is allowed.
see
#matchData
see
#addDataScheme

        if (mDataAuthorities == null) mDataAuthorities =
                new ArrayList<AuthorityEntry>();
        if (port != null) port = port.intern();
        mDataAuthorities.add(new AuthorityEntry(host.intern(), port));
    
public final voidaddDataPath(java.lang.String path, int type)
Add a new Intent data oath to match against. The filter must include one or more schemes (via {@link #addDataScheme}) and one or more authorities (via {@link #addDataAuthority}) 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.

param
path Either a raw string that must exactly match the file path, or a simple pattern, depending on type.
param
type Determines how path will be compared to determine a match: either {@link PatternMatcher#PATTERN_LITERAL}, {@link PatternMatcher#PATTERN_PREFIX}, or {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
see
#matchData
see
#addDataScheme
see
#addDataAuthority

        if (mDataPaths == null) mDataPaths = new ArrayList<PatternMatcher>();
        mDataPaths.add(new PatternMatcher(path.intern(), type));
    
public final voidaddDataScheme(java.lang.String scheme)
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.

param
scheme Name of the scheme to match, i.e. "http".
see
#matchData

        if (mDataSchemes == null) mDataSchemes = new ArrayList<String>();
        if (!mDataSchemes.contains(scheme)) {
            mDataSchemes.add(scheme.intern());
        }
    
public final voidaddDataType(java.lang.String type)
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.

Throws {@link MalformedMimeTypeException} if the given MIME type is not syntactically correct.

param
type Name of the data type to match, i.e. "vnd.android.cursor.dir/person".
see
#matchData

        final int slashpos = type.indexOf('/");
        final int typelen = type.length();
        if (slashpos > 0 && typelen >= slashpos+2) {
            if (mDataTypes == null) mDataTypes = new ArrayList<String>();
            if (typelen == slashpos+2 && type.charAt(slashpos+1) == '*") {
                String str = type.substring(0, slashpos);
                if (!mDataTypes.contains(str)) {
                    mDataTypes.add(str.intern());
                }
                mHasPartialTypes = true;
            } else {
                if (!mDataTypes.contains(type)) {
                    mDataTypes.add(type.intern());
                }
            }
            return;
        }

        throw new MalformedMimeTypeException(type);
    
private static java.lang.String[]addStringToSet(java.lang.String[] set, java.lang.String string, int[] lengths, int lenPos)

        if (findStringInSet(set, string, lengths, lenPos) >= 0) return set;
        if (set == null) {
            set = new String[2];
            set[0] = string;
            lengths[lenPos] = 1;
            return set;
        }
        final int N = lengths[lenPos];
        if (N < set.length) {
            set[N] = string;
            lengths[lenPos] = N+1;
            return set;
        }

        String[] newSet = new String[(N*3)/2 + 2];
        System.arraycopy(set, 0, newSet, 0, N);
        set = newSet;
        set[N] = string;
        lengths[lenPos] = N+1;
        return set;
    
public final java.util.IteratorauthoritiesIterator()
Return an iterator over the filter's data authorities.

        return mDataAuthorities != null ? mDataAuthorities.iterator() : null;
    
public final java.util.IteratorcategoriesIterator()
Return an iterator over the filter's categories.

        return mCategories != null ? mCategories.iterator() : null;
    
public final intcountActions()
Return the number of actions in the filter.

        return mActions.size();
    
public final intcountCategories()
Return the number of categories in the filter.

        return mCategories != null ? mCategories.size() : 0;
    
public final intcountDataAuthorities()
Return the number of data authorities in the filter.

        return mDataAuthorities != null ? mDataAuthorities.size() : 0;
    
public final intcountDataPaths()
Return the number of data paths in the filter.

        return mDataPaths != null ? mDataPaths.size() : 0;
    
public final intcountDataSchemes()
Return the number of data schemes in the filter.

        return mDataSchemes != null ? mDataSchemes.size() : 0;
    
public final intcountDataTypes()
Return the number of data types in the filter.

        return mDataTypes != null ? mDataTypes.size() : 0;
    
public static android.content.IntentFiltercreate(java.lang.String action, java.lang.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 {@link MalformedMimeTypeException} exception that the constructor can call and turns it into a runtime exception.

param
action The action to match, i.e. Intent.ACTION_VIEW.
param
dataType The type to match, i.e. "vnd.android.cursor.dir/person".
return
A new IntentFilter for the given action and type.
see
#IntentFilter(String, String)

        try {
            return new IntentFilter(action, dataType);
        } catch (MalformedMimeTypeException e) {
            throw new RuntimeException("Bad MIME type", e);
        }
    
public booleandebugCheck()
For debugging -- perform a check on the filter, return true if it passed or false if it failed. {@hide}

        return true;

        // This code looks for intent filters that do not specify data.
        /*
        if (mActions != null && mActions.size() == 1
                && mActions.contains(Intent.ACTION_MAIN)) {
            return true;
        }

        if (mDataTypes == null && mDataSchemes == null) {
            Log.w("IntentFilter", "QUESTIONABLE INTENT FILTER:");
            dump(Log.WARN, "IntentFilter", "  ");
            return false;
        }

        return true;
        */
    
public final intdescribeContents()


        
        return 0;
    
public voiddump(android.util.Printer du, java.lang.String prefix)

        if (mActions.size() > 0) {
            Iterator<String> it = mActions.iterator();
            while (it.hasNext()) {
               du.println(prefix + "Action: \"" + it.next() + "\"");
            }
        }
        if (mCategories != null) {
            Iterator<String> it = mCategories.iterator();
            while (it.hasNext()) {
                du.println(prefix + "Category: \"" + it.next() + "\"");
            }
        }
        if (mDataSchemes != null) {
            Iterator<String> it = mDataSchemes.iterator();
            while (it.hasNext()) {
                du.println(prefix + "Data Scheme: \"" + it.next() + "\"");
            }
        }
        if (mDataAuthorities != null) {
            Iterator<AuthorityEntry> it = mDataAuthorities.iterator();
            while (it.hasNext()) {
                AuthorityEntry ae = it.next();
                du.println(prefix + "Data Authority: \"" + ae.mHost + "\":"
                        + ae.mPort + (ae.mWild ? " WILD" : ""));
            }
        }
        if (mDataPaths != null) {
            Iterator<PatternMatcher> it = mDataPaths.iterator();
            while (it.hasNext()) {
                PatternMatcher pe = it.next();
                du.println(prefix + "Data Path: \"" + pe + "\"");
            }
        }
        if (mDataTypes != null) {
            Iterator<String> it = mDataTypes.iterator();
            while (it.hasNext()) {
                du.println(prefix + "Data Type: \"" + it.next() + "\"");
            }
        }
        du.println(prefix + "mPriority=" + mPriority
                + ", mHasPartialTypes=" + mHasPartialTypes);
    
private final booleanfindMimeType(java.lang.String type)

        final ArrayList<String> t = mDataTypes;

        if (type == null) {
            return false;
        }

        if (t.contains(type)) {
            return true;
        }

        // Deal with an Intent wanting to match every type in the IntentFilter.
        final int typeLength = type.length();
        if (typeLength == 3 && type.equals("*/*")) {
            return !t.isEmpty();
        }

        // Deal with this IntentFilter wanting to match every Intent type.
        if (mHasPartialTypes && t.contains("*")) {
            return true;
        }

        final int slashpos = type.indexOf('/");
        if (slashpos > 0) {
            if (mHasPartialTypes && t.contains(type.substring(0, slashpos))) {
                return true;
            }
            if (typeLength == slashpos+2 && type.charAt(slashpos+1) == '*") {
                // Need to look through all types for one that matches
                // our base...
                final Iterator<String> it = t.iterator();
                while (it.hasNext()) {
                    String v = it.next();
                    if (type.regionMatches(0, v, 0, slashpos+1)) {
                        return true;
                    }
                }
            }
        }

        return false;
    
private static intfindStringInSet(java.lang.String[] set, java.lang.String string, int[] lengths, int lenPos)


    // These functions are the start of more optimized code for managing
    // the string sets...  not yet implemented.

          
                
        if (set == null) return -1;
        final int N = lengths[lenPos];
        for (int i=0; i<N; i++) {
            if (set[i].equals(string)) return i;
        }
        return -1;
    
public final java.lang.StringgetAction(int index)
Return an action in the filter.

        return mActions.get(index);
    
public final java.lang.StringgetCategory(int index)
Return a category in the filter.

        return mCategories.get(index);
    
public final android.content.IntentFilter$AuthorityEntrygetDataAuthority(int index)
Return a data authority in the filter.

        return mDataAuthorities.get(index);
    
public final android.os.PatternMatchergetDataPath(int index)
Return a data path in the filter.

        return mDataPaths.get(index);
    
public final java.lang.StringgetDataScheme(int index)
Return a data scheme in the filter.

        return mDataSchemes.get(index);
    
public final java.lang.StringgetDataType(int index)
Return a data type in the filter.

        return mDataTypes.get(index);
    
public final intgetPriority()
Return the priority of this filter.

return
The priority of the filter.
see
#setPriority

        return mPriority;
    
public final booleanhasAction(java.lang.String action)
Is the given action included in the filter? Note that if the filter does not include any actions, false will always be returned.

param
action The action to look for.
return
True if the action is explicitly mentioned in the filter.

        return mActions.contains(action);
    
public final booleanhasCategory(java.lang.String category)
Is the given category included in the filter?

param
category The category that the filter supports.
return
True if the category is explicitly mentioned in the filter.

        return mCategories != null && mCategories.contains(category);
    
public final booleanhasDataAuthority(android.net.Uri data)
Is the given data authority included in the filter? Note that if the filter does not include any authorities, false will always be returned.

param
data The data whose authority is being looked for.
return
Returns true if the data string matches an authority listed in the filter.

        return matchDataAuthority(data) >= 0;
    
public final booleanhasDataPath(java.lang.String data)
Is the given data path included in the filter? Note that if the filter does not include any paths, false will always be returned.

param
data The data path to look for. This is without the scheme prefix.
return
True if the data string matches a path listed in the filter.

        if (mDataPaths == null) {
            return false;
        }
        Iterator<PatternMatcher> i = mDataPaths.iterator();
        while (i.hasNext()) {
            final PatternMatcher pe = i.next();
            if (pe.match(data)) {
                return true;
            }
        }
        return false;
    
public final booleanhasDataScheme(java.lang.String scheme)
Is the given data scheme included in the filter? Note that if the filter does not include any scheme, false will always be returned.

param
scheme The data scheme to look for.
return
True if the scheme is explicitly mentioned in the filter.

        return mDataSchemes != null && mDataSchemes.contains(scheme);
    
public final booleanhasDataType(java.lang.String type)
Is the given data type included in the filter? Note that if the filter does not include any type, false will always be returned.

param
type The data type to look for.
return
True if the type is explicitly mentioned in the filter.

        return mDataTypes != null && findMimeType(type);
    
public final intmatch(ContentResolver resolver, Intent intent, boolean resolve, java.lang.String logTag)
Test whether this filter matches the given intent.

param
intent The Intent to compare against.
param
resolve If true, the intent's type will be resolved by calling Intent.resolveType(); otherwise a simple match against Intent.type will be performed.
param
logTag Tag to use in debugging messages.
return
Returns either a valid match constant (a combination of {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}), or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match, {@link #NO_MATCH_DATA} if the scheme/path didn't match, {@link #NO_MATCH_ACTION if the action didn't match, or {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
return
How well the filter matches. Negative if it doesn't match, zero or positive positive value if it does with a higher value representing a better match.
see
#match(String, String, String, android.net.Uri , Set, String)

        String type = resolve ? intent.resolveType(resolver) : intent.getType();
        return match(intent.getAction(), type, intent.getScheme(),
                     intent.getData(), intent.getCategories(), logTag);
    
public final intmatch(java.lang.String action, java.lang.String type, java.lang.String scheme, android.net.Uri data, java.util.Set categories, java.lang.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 {@link IntentFilter}; in that case, the match result returned will be as per {@link #matchData}.

param
action The intent action to match against (Intent.getAction).
param
type The intent type to match against (Intent.resolveType()).
param
scheme The data scheme to match against (Intent.getScheme()).
param
data The data URI to match against (Intent.getData()).
param
categories The categories to match against (Intent.getCategories()).
param
logTag Tag to use in debugging messages.
return
Returns either a valid match constant (a combination of {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}), or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match, {@link #NO_MATCH_DATA} if the scheme/path didn't match, {@link #NO_MATCH_ACTION if the action didn't match, or {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
see
#matchData
see
Intent#getAction
see
Intent#resolveType
see
Intent#getScheme
see
Intent#getData
see
Intent#getCategories

        if (action != null && !matchAction(action)) {
            if (Config.LOGV) Log.v(
                logTag, "No matching action " + action + " for " + this);
            return NO_MATCH_ACTION;
        }

        int dataMatch = matchData(type, scheme, data);
        if (dataMatch < 0) {
            if (Config.LOGV) {
                if (dataMatch == NO_MATCH_TYPE) {
                    Log.v(logTag, "No matching type " + type
                          + " for " + this);
                }
                if (dataMatch == NO_MATCH_DATA) {
                    Log.v(logTag, "No matching scheme/path " + data
                          + " for " + this);
                }
            }
            return dataMatch;
        }

        String categoryMatch = matchCategories(categories);
        if (categoryMatch != null) {
            if (Config.LOGV) Log.v(
                logTag, "No matching category "
                + categoryMatch + " for " + this);
            return NO_MATCH_CATEGORY;
        }

        // It would be nice to treat container activities as more
        // important than ones that can be embedded, but this is not the way...
        if (false) {
            if (categories != null) {
                dataMatch -= mCategories.size() - categories.size();
            }
        }

        return dataMatch;
    
public final booleanmatchAction(java.lang.String action)
Match this filter against an Intent's action. If the filter does not specify any actions, the match will always fail.

param
action The desired action to look for.
return
True if the action is listed in the filter or the filter does not specify any actions.

        if (action == null || mActions == null || mActions.size() == 0) {
            return false;
        }
        return mActions.contains(action);
    
public final java.lang.StringmatchCategories(java.util.Set categories)
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.

param
categories The categories included in the intent, as returned by Intent.getCategories().
return
If all categories match (success), null; else the name of the first category that didn't match.

        if (categories == null) {
            return null;
        }

        Iterator<String> it = categories.iterator();

        if (mCategories == null) {
            return it.hasNext() ? it.next() : null;
        }

        while (it.hasNext()) {
            final String category = it.next();
            if (!mCategories.contains(category)) {
                return category;
            }
        }

        return null;
    
public final intmatchData(java.lang.String type, java.lang.String scheme, android.net.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.

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.

param
type The desired data type to look for, as returned by Intent.resolveType().
param
scheme The desired data scheme to look for, as returned by Intent.getScheme().
param
data The full data string to match against, as supplied in Intent.data.
return
Returns either a valid match constant (a combination of {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}), or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match or {@link #NO_MATCH_DATA} if the scheme/path didn't match.
see
#match

        final ArrayList<String> types = mDataTypes;
        final ArrayList<String> schemes = mDataSchemes;
        final ArrayList<AuthorityEntry> authorities = mDataAuthorities;
        final ArrayList<PatternMatcher> paths = mDataPaths;

        int match = MATCH_CATEGORY_EMPTY;

        if (types == null && schemes == null) {
            return ((type == null && data == null)
                ? (MATCH_CATEGORY_EMPTY+MATCH_ADJUSTMENT_NORMAL) : NO_MATCH_DATA);
        }

        if (schemes != null) {
            if (schemes.contains(scheme != null ? scheme : "")) {
                match = MATCH_CATEGORY_SCHEME;
            } else {
                return NO_MATCH_DATA;
            }

            if (authorities != null) {
                int authMatch = matchDataAuthority(data);
                if (authMatch >= 0) {
                    if (paths == null) {
                        match = authMatch;
                    } else if (hasDataPath(data.getPath())) {
                        match = MATCH_CATEGORY_PATH;
                    } else {
                        return NO_MATCH_DATA;
                    }
                } else {
                    return NO_MATCH_DATA;
                }
            }
        } else {
            // Special case: match either an Intent with no data URI,
            // or with a scheme: URI.  This is to give a convenience for
            // the common case where you want to deal with data in a
            // content provider, which is done by type, and we don't want
            // to force everyone to say they handle content: or file: URIs.
            if (scheme != null && !"".equals(scheme)
                    && !"content".equals(scheme)
                    && !"file".equals(scheme)) {
                return NO_MATCH_DATA;
            }
        }

        if (types != null) {
            if (findMimeType(type)) {
                match = MATCH_CATEGORY_TYPE;
            } else {
                return NO_MATCH_TYPE;
            }
        } else {
            // If no MIME types are specified, then we will only match against
            // an Intent that does not have a MIME type.
            if (type != null) {
                return NO_MATCH_TYPE;
            }
        }

        return match + MATCH_ADJUSTMENT_NORMAL;
    
public final intmatchDataAuthority(android.net.Uri data)
Match this intent filter against the given Intent data. This ignores the data scheme -- unlike {@link #matchData}, the authority will match regardless of whether there is a matching scheme.

param
data The data whose authority is being looked for.
return
Returns either {@link #MATCH_CATEGORY_HOST}, {@link #MATCH_CATEGORY_PORT}, {@link #NO_MATCH_DATA}.

        if (mDataAuthorities == null) {
            return NO_MATCH_DATA;
        }
        Iterator<AuthorityEntry> i = mDataAuthorities.iterator();
        while (i.hasNext()) {
            final AuthorityEntry ae = i.next();
            int match = ae.match(data);
            if (match >= 0) {
                return match;
            }
        }
        return NO_MATCH_DATA;
    
public final java.util.IteratorpathsIterator()
Return an iterator over the filter's data paths.

        return mDataPaths != null ? mDataPaths.iterator() : null;
    
public voidreadFromXml(org.xmlpull.v1.XmlPullParser parser)

        int outerDepth = parser.getDepth();
        int type;
        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
               && (type != XmlPullParser.END_TAG
                       || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG
                    || type == XmlPullParser.TEXT) {
                continue;
            }

            String tagName = parser.getName();
            if (tagName.equals(ACTION_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
                    addAction(name);
                }
            } else if (tagName.equals(CAT_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
                    addCategory(name);
                }
            } else if (tagName.equals(TYPE_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
                    try {
                        addDataType(name);
                    } catch (MalformedMimeTypeException e) {
                    }
                }
            } else if (tagName.equals(SCHEME_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
                    addDataScheme(name);
                }
            } else if (tagName.equals(AUTH_STR)) {
                String host = parser.getAttributeValue(null, HOST_STR);
                String port = parser.getAttributeValue(null, PORT_STR);
                if (host != null) {
                    addDataAuthority(host, port);
                }
            } else if (tagName.equals(PATH_STR)) {
                String path = parser.getAttributeValue(null, LITERAL_STR);
                if (path != null) {
                    addDataPath(path, PatternMatcher.PATTERN_LITERAL);
                } else if ((path=parser.getAttributeValue(null, PREFIX_STR)) != null) {
                    addDataPath(path, PatternMatcher.PATTERN_PREFIX);
                } else if ((path=parser.getAttributeValue(null, SGLOB_STR)) != null) {
                    addDataPath(path, PatternMatcher.PATTERN_SIMPLE_GLOB);
                }
            } else {
                Log.w("IntentFilter", "Unknown tag parsing IntentFilter: " + tagName);
            }
            XmlUtils.skipCurrentTag(parser);
        }
    
private static java.lang.String[]removeStringFromSet(java.lang.String[] set, java.lang.String string, int[] lengths, int lenPos)

        int pos = findStringInSet(set, string, lengths, lenPos);
        if (pos < 0) return set;
        final int N = lengths[lenPos];
        if (N > (set.length/4)) {
            int copyLen = N-(pos+1);
            if (copyLen > 0) {
                System.arraycopy(set, pos+1, set, pos, copyLen);
            }
            set[N-1] = null;
            lengths[lenPos] = N-1;
            return set;
        }

        String[] newSet = new String[set.length/3];
        if (pos > 0) System.arraycopy(set, 0, newSet, 0, pos);
        if ((pos+1) < N) System.arraycopy(set, pos+1, newSet, pos, N-(pos+1));
        return newSet;
    
public final java.util.IteratorschemesIterator()
Return an iterator over the filter's data schemes.

        return mDataSchemes != null ? mDataSchemes.iterator() : null;
    
public final voidsetPriority(int priority)
Modify priority of this filter. The default priority is 0. Positive values will be before the default, lower values will be after it. Applications must use a value that is larger than {@link #SYSTEM_LOW_PRIORITY} and smaller than {@link #SYSTEM_HIGH_PRIORITY} .

param
priority The new priority value.
see
#getPriority
see
#SYSTEM_LOW_PRIORITY
see
#SYSTEM_HIGH_PRIORITY

        mPriority = priority;
    
public final java.util.IteratortypesIterator()
Return an iterator over the filter's data types.

        return mDataTypes != null ? mDataTypes.iterator() : null;
    
public final voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeStringList(mActions);
        if (mCategories != null) {
            dest.writeInt(1);
            dest.writeStringList(mCategories);
        } else {
            dest.writeInt(0);
        }
        if (mDataSchemes != null) {
            dest.writeInt(1);
            dest.writeStringList(mDataSchemes);
        } else {
            dest.writeInt(0);
        }
        if (mDataTypes != null) {
            dest.writeInt(1);
            dest.writeStringList(mDataTypes);
        } else {
            dest.writeInt(0);
        }
        if (mDataAuthorities != null) {
            final int N = mDataAuthorities.size();
            dest.writeInt(N);
            for (int i=0; i<N; i++) {
                mDataAuthorities.get(i).writeToParcel(dest);
            }
        } else {
            dest.writeInt(0);
        }
        if (mDataPaths != null) {
            final int N = mDataPaths.size();
            dest.writeInt(N);
            for (int i=0; i<N; i++) {
                mDataPaths.get(i).writeToParcel(dest, 0);
            }
        } else {
            dest.writeInt(0);
        }
        dest.writeInt(mPriority);
        dest.writeInt(mHasPartialTypes ? 1 : 0);
    
public voidwriteToXml(org.xmlpull.v1.XmlSerializer serializer)
Write the contents of the IntentFilter as an XML stream.

        int N = countActions();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, ACTION_STR);
            serializer.attribute(null, NAME_STR, mActions.get(i));
            serializer.endTag(null, ACTION_STR);
        }
        N = countCategories();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, CAT_STR);
            serializer.attribute(null, NAME_STR, mCategories.get(i));
            serializer.endTag(null, CAT_STR);
        }
        N = countDataTypes();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, TYPE_STR);
            String type = mDataTypes.get(i);
            if (type.indexOf('/") < 0) type = type + "/*";
            serializer.attribute(null, NAME_STR, type);
            serializer.endTag(null, TYPE_STR);
        }
        N = countDataSchemes();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, SCHEME_STR);
            serializer.attribute(null, NAME_STR, mDataSchemes.get(i));
            serializer.endTag(null, SCHEME_STR);
        }
        N = countDataAuthorities();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, AUTH_STR);
            AuthorityEntry ae = mDataAuthorities.get(i);
            serializer.attribute(null, HOST_STR, ae.getHost());
            if (ae.getPort() >= 0) {
                serializer.attribute(null, PORT_STR, Integer.toString(ae.getPort()));
            }
            serializer.endTag(null, AUTH_STR);
        }
        N = countDataPaths();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, PATH_STR);
            PatternMatcher pe = mDataPaths.get(i);
            switch (pe.getType()) {
                case PatternMatcher.PATTERN_LITERAL:
                    serializer.attribute(null, LITERAL_STR, pe.getPath());
                    break;
                case PatternMatcher.PATTERN_PREFIX:
                    serializer.attribute(null, PREFIX_STR, pe.getPath());
                    break;
                case PatternMatcher.PATTERN_SIMPLE_GLOB:
                    serializer.attribute(null, SGLOB_STR, pe.getPath());
                    break;
            }
            serializer.endTag(null, PATH_STR);
        }