Android 中的 URI 匹配器问题

发布于 2024-10-12 05:21:54 字数 470 浏览 4 评论 0原文

我有一个权限字符串定义如下:

public final static String AUTHORITY = "dsndata.sds2mobile.jobprovider";

后面是 UriMatcher 的版本:

uriMatcher.addURI(JobMetaData.AUTHORITY, "/JobNames/*",
                      JOBNAME_SINGLE_URI);

传递到交换机的 uri 是:

content://dsndata.sds2mobile.jobprovider/JobNames/test

这会通过交换机并达到默认值(抛出 IllegalArgumentException)。

我错过了什么吗?我进行了搜索,但找不到任何可以解释不匹配的原因。

I have an authority string defined as such:

public final static String AUTHORITY = "dsndata.sds2mobile.jobprovider";

Followed by an edition to the UriMatcher:

uriMatcher.addURI(JobMetaData.AUTHORITY, "/JobNames/*",
                      JOBNAME_SINGLE_URI);

The uri that gets passed to the switch is:

content://dsndata.sds2mobile.jobprovider/JobNames/test

This falls through the switch and hits the default (which throws an IllegalArgumentException).

Am I missing something? I've searched and can't find anything that would account for the mismatch.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慈悲佛祖 2024-10-19 05:21:54

我对 IllegalArgumentException 也遇到了同样的问题。即使那些调试 Uri 的人也是一样的! [让我发疯]。如果您首先定义了 */ match ,那么它似乎会匹配并阻止其他人匹配。 订单很重要!!

我重新订购了,“external_warning_id”现在工作正常。

//putting it first as /* seems to get matched first
    URL_MATCHER.addURI(AUTHORITY, TABLE_NAME.toLowerCase() + "/external_warning_id" + "/*",
            EXTERNAL_WARNING_ID);

// was the first entry in static block
URL_MATCHER.addURI(AUTHORITY, TABLE_NAME.toLowerCase() + "/*", WARNING__ID);

I had the same problem too with IllegalArgumentException. Even those have debugging the Uri's were the same! [drove me crazy]. If you have defined */ match first that seems to match and prevent others from matching. ORDER IS IMPORTANT!!

I reordered and the 'external_warning_id' now works fine.

//putting it first as /* seems to get matched first
    URL_MATCHER.addURI(AUTHORITY, TABLE_NAME.toLowerCase() + "/external_warning_id" + "/*",
            EXTERNAL_WARNING_ID);

// was the first entry in static block
URL_MATCHER.addURI(AUTHORITY, TABLE_NAME.toLowerCase() + "/*", WARNING__ID);
绻影浮沉 2024-10-19 05:21:54

尝试删除前导斜杠:

uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/*",
                  JOBNAME_SINGLE_URI);

而不是

uriMatcher.addURI(JobMetaData.AUTHORITY, "/JobNames/*",
                  JOBNAME_SINGLE_URI);

(更新)

使用提供的代码,我通过将该行移动到顶部来使其工作。定义的顺序很重要,似乎您的其他一些匹配器在某种程度上发生了冲突。不管怎样,把它移到顶部是有效的。

Try removing the leading slash:

uriMatcher.addURI(JobMetaData.AUTHORITY, "JobNames/*",
                  JOBNAME_SINGLE_URI);

instead of

uriMatcher.addURI(JobMetaData.AUTHORITY, "/JobNames/*",
                  JOBNAME_SINGLE_URI);

(Update)

With the code supplied, I got it working by moving that line to the top. The order of definition is important and it seems some of your other matchers somehow conflict. Anyway, moving it to the top worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文