Code
/** * Match This filter against an Intent ' s data ( type, scheme , and path). If * The filter does not specify any types anddoes not specify any * schemes/paths, theMatchwould only succeedifThe intent does not * also specify a type or data. If the Filter does not Specify any schemes,* It'll implicitlyMatchIntents withNo scheme,orThe 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.* * <p>be aware that to MatchAgainst an authority, you must also specify aBase* Scheme the Authority isinch. ToMatchAgainst a data path, both a scheme * andAuthority must be specified. If The filter does not specify any * typesorSchemes that it matches against, it's considered tobe empty * (any authorityorData path given is ignored, as ifIt were empty as* well). * * <p><em>note:mime type, Uri scheme, and host name matching inch the* Android Framework is case-sensitive, unlike the formal RFC definitions. * As a result, you should always write these elements withlower case Letters, * andNormalize any MIME typesorUris you receive from * Outside ofAndroid toEnsure these elements is 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 toLook for, asReturned by * Intent.getscheme (). * @param data the full data string to MatchAgainst, asSuppliedinch* Intent.data. * * @returnReturns either a validMatchConstant (a combination of* {@link #MATCH_CATEGORY_MASK} and{@link #MATCH_ADJUSTMENT_MASK}), *orOne ofThe error codes {@link #NO_MATCH_TYPE}ifThe type didn't match *or{@link #NO_MATCH_DATA}ifThe Scheme/path didn ' tMatch. * * @see #Match*/ PublicFinal int Matchdata (String type, String scheme, Uri data) {Final arraylist<string> types = mdatatypes; Final arraylist<string> schemes = Mdataschemes; IntMatch= Match_category_empty;//1. If the filter's type scheme is empty and intent's type data is empty then match //Otherwise 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 filter's schemes is not empty and the intent scheme is included in it, then the subsequent judgment is made; //Otherwise does not match if(schemes.contains (Scheme! =NULL? Scheme:"")) {Match= Match_category_scheme; }Else{returnNo_match_data; } final arraylist<patternmatcher> schemespecificparts = mdataschemespecificparts;if(Schemespecificparts! =NULL) {//3. If Schemespecificparts is not empty, use the schemespecificpart of data to make a match //and modify the match value. 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 matching SSP, we need to match an authority.Final arraylist<authorityentry> authorities = Mdataauthorities;//4. If Schemespecificpart (SSP) does not match, match authority //is to judge the host port part if(Authorities! =NULL) {int authmatch = matchdataauthority (data);if(Authmatch >=0) {//5. The host port matches, then the path match is continuedFinal arraylist<patternmatcher> paths = mdatapaths;if(Paths = =NULL) {Match= Authmatch; }Else if(Hasdatapath (Data.getpath ())) {Match= Match_category_path; }Else{returnNo_match_data; } }Else{//Host port does not match returnNo_match_data; } } }//If Neither an SSP or an authority matched, we ' re -done. if(Match= = No_match_data) {returnNo_match_data; } }Else{//Schemespecificparts of filter is not empty and matches intent Schemespecificpart //If scheme is not "" "Content" "file" does not match; //Special Case:match either a Intent with no data URI, //or with a scheme:uri. Give a convenience for //The common case where you want to deal with data in a //content provider, which is do 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)) {returnNo_match_data; } }if(Types! =NULL) {//6. Type is MIME //If type is not empty, determine if the type of filter and intent are inclusive, otherwise it will not match if(Findmimetype ( type)) { Match= Match_category_type; }Else{returnNo_match_type; } }Else{//If No MIME types is specified, then we'll only match against //An Intent this does not has a MIME type. if( type ! = NULL) {//If the types collection of filter is empty, but intent is not empty, does not match returnNo_match_type; } }return Match+ Match_adjustment_normal;}