1

我已经尝试了一段时间,但似乎无法解决我的 URI 匹配问题。任何帮助是极大的赞赏。

这是我对内容 uri 和 uri 匹配器的声明:

private static final String AUTHORITY = "edu.uprm.civil.db";

public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

private static UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
    sURIMatcher.addURI(AUTHORITY, "/get-table" + "/*", TABLE_REQUEST_CODE);
    sURIMatcher.addURI(AUTHORITY, "/get-row" + "/*", ROW_REQUEST_CODE);
    sURIMatcher.addURI(AUTHORITY, "/search" + "/*", TABLE_SEARCH_REQUEST_CODE);
}

并且被传递的 uri 在以下代码中构造:

    Uri.Builder uriBuilder = DBContentProvider.CONTENT_URI.buildUpon();

    switch(id){
    case LOADER_GET_TABLE_ID :
        uriBuilder.appendPath("get-table");
        uriBuilder.appendPath("q");
        uriBuilder.appendQueryParameter("table", formID);
        return new CursorLoader(context, uriBuilder.build(), null, null, null, null);
    case ...

我调试了该方法,并且能够看到参数中包含的 URI,但它从不匹配。

uri是怎么来的:

content://edu.uprm.civil.db/get-table/q?table=150

如果您需要更多信息,请告诉我,这让我很头疼......

4

1 回答 1

0

修改您的规则并从路径参数UriMatcher中删除开始:/

sURIMatcher.addURI(AUTHORITY, "get-table" + "/*", TABLE_REQUEST_CODE);
sURIMatcher.addURI(AUTHORITY, "get-row" + "/*", ROW_REQUEST_CODE);
sURIMatcher.addURI(AUTHORITY, "search" + "/*", TABLE_SEARCH_REQUEST_CODE);
于 2012-04-21T09:56:53.670 回答