Is UriMatcher capable of matching custom http links?
I would like to use UriMatcher
to match custom http links.
I have following code:
UriMatch开发者_如何学Cer mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mUriMatcher.addURI("myLink", "http://a.b.c/?id=", 1);
mUriMatcher.addURI("myLink", "http://d.e.f/?id=", 2);
int match = mUriMatcher.match(Uri.parse("http://a.b.c/?id=123"));
But I always get "-1" in match result...
UriMatcher matches Uris of the form:
scheme://<authority>/<path>
It ignores the query string (anything appearing after ? in the url)
You register with the matcher using:
mUriMatcher.addURI(authority, path, result);
So, in your simple example above, you can not distinguish between the same URL with or without a query string, but you can match on the domain name. Use:
mUriMatcher.addURI('a.b.c', '/', 1);
mUriMatcher.addURI('d.e.f', '/', 2);
You can use UrlQuerySanitizer within each match handler to decide whether the query things you need are present or not.
精彩评论