Code
/*** 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 shortming a MI ME-type only match ). if the filter * does not specify any MIME types, the Intent also must not specify a MIME * type. ** <p> 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 conside Red to be empty * (any authority or data path given is ignored, as if it were empty as * well ). ** <p> <em> 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 shoshould always write these elements with lower case letters, * and normalize any MIME types or Uris you receive from * outside of Android to e Nsure these elements are lower case before * supplying them here. </em> </p> ** @ 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 combinati On 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 */public final int matchData (String type, String scheme, Uri data) {final ArrayList <String> types = mDataTypes; final ArrayList <String> schemes = mDataSchemes; int match = MATCH_CATEGORY_EMPTY; // 1. if the type scheme of the filter is empty and the type data of the intent is empty, the filter matches. // otherwise, the filter does not match if (types = null & schemes = null) {return (type = null & data = null )? (MATCH_CATEGORY_EMPTY + MATCH_ADJUSTMENT_NORMAL): NO_MATCH_DATA);} if (schemes! = Null) {// 2. if the schemes of the filter is not empty and the scheme of the intent is included in it, the system will make a further judgment. // otherwise, if (schemes. contains (scheme! = Null? Scheme: "") {match = MATCH_CATEGORY_SCHEME;} else {return NO_MATCH_DATA;} final ArrayList <PatternMatcher> schemeSpecificParts = partition; if (schemeSpecificParts! = Null) {// 3. If schemeSpecificParts is not empty, use SchemeSpecificPart of data to perform matching // and modify the value of match. Uri Syntax: [scheme:] scheme-specific-part [# fragment]/[scheme:] [// authority] [path] [? Query] [# fragment] match = hasDataSchemeSpecificPart (data. getSchemeSpecificPart ())? MATCH_CATEGORY_SCHEME_SPECIFIC_PART: NO_MATCH_DATA;} if (match! = MATCH_CATEGORY_SCHEME_SPECIFIC_PART) {// If there isn' t any matching ssp, we need to match an authority. final ArrayList <AuthorityEntry> authorities = mDataAuthorities; // 4. if schemeSpecificPart (ssp) does not match, it must match authority // that is, it is used to determine the part of the host port if (authorities! = Null) {int authMatch = matchDataAuthority (data); if (authMatch> = 0) {// 5. if the host port matches, the final ArrayList <PatternMatcher> paths = mDataPaths; if (paths = null) {match = authMatch;} else if (hasDataPath (data. getPath () {match = MATCH_CATEGORY_PATH;} else {return NO_MATCH_DATA ;}} else {// The host port does not match return NO_MATCH_DATA ;}}} // If neither an ssp nor an authority matched, We're re done. if (match = NO_MATCH_DATA) {return NO_MATCH_DATA ;}} else {// The schemeSpecificParts of the filter is not empty and matches the SchemeSpecificPart of the intent, // If scheme is not "content" "file", it does not match; otherwise, it will continue to be judged. // 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 ty Pe, 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) {// 6. type: MIME // if the type is not empty, it determines whether the type of the filter and intent is inclusive. Otherwise, it does not match 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) {// If the filter's types set is null, but the intent is not empty, return NO_MATCH_TYPE;} return match + MATCH_ADJUSTMENT_NORMAL ;}