2012-04-21 97 views
1

我一直在嘗試一段時間,但我似乎無法解決我的URI匹配問題。任何幫助是極大的讚賞。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 

如果您需要任何更多的信息,請讓我知道,它一直對我頭疼......

回答

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); 
+0

非常感謝您,這些修改非常完美! – DanyBoricua 2012-04-21 14:02:22