我现在已经尝试了一段时间,但我似乎无法解决我的URI匹配问题。非常感谢任何帮助。
这是我对内容uri和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);
}
传递的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 :(得分: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);