URI Matching on content provider not matching correctly

a 夏天 提交于 2019-12-11 06:38:11

问题


I've been trying now for a while but I can't seem to resolve my URI matching problem. Any help is greatly appreciated.

Here is my declaration of the content uri and the uri matcher:

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);
}

And the uri being passed is contructed in the following code:

    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 ...

I debug the method and I am able to see the URI as it comes in the parameter, but it never matches.

How the uri comes:

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

If you need any more info please let me know, it's been a headache for me...


回答1:


Modify the rules for your UriMatcher and remove the starting / from the path parameter:

sURIMatcher.addURI(AUTHORITY, "get-table" + "/*", TABLE_REQUEST_CODE);
sURIMatcher.addURI(AUTHORITY, "get-row" + "/*", ROW_REQUEST_CODE);
sURIMatcher.addURI(AUTHORITY, "search" + "/*", TABLE_SEARCH_REQUEST_CODE);


来源:https://stackoverflow.com/questions/10256773/uri-matching-on-content-provider-not-matching-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!