gpt4 book ai didi

android - UriMatcher 是否能够匹配自定义 http 链接?

转载 作者:行者123 更新时间:2023-12-05 00:17:46 26 4
gpt4 key购买 nike

我想使用 UriMatcher匹配自定义 http 链接。

我有以下代码:

UriMatcher 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"));

但我总是在比赛结果中得到“-1”......

最佳答案

UriMatcher 匹配以下形式的 Uris:

scheme://<authority>/<path>

它忽略查询字符串(在 ? 之后出现的任何内容)

您使用以下方式向匹配器注册:
mUriMatcher.addURI(authority, path, result);

因此,在上面的简单示例中,您无法区分带有或不带有查询字符串的相同 URL,但您可以匹配域名。利用:
mUriMatcher.addURI('a.b.c', '/', 1);
mUriMatcher.addURI('d.e.f', '/', 2);

您可以在每个匹配处理程序中使用 UrlQuerySanitizer 来确定您需要的查询内容是否存在。

关于android - UriMatcher 是否能够匹配自定义 http 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4204816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com