我有以下URI设置:
public static final String AUTHORITY = "content://com.danny.servercontentprovider";
// Query URI
private static final int SERVER = 100;
private static final int SERVER_ID = 101;
// Create URI matcher
private static final UriMatcher sURIMatcher = new UriMatcher(
UriMatcher.NO_MATCH);
static {
sURIMatcher.addURI(AUTHORITY, "server", SERVER);
sURIMatcher
.addURI(AUTHORITY, "server/#", SERVER_ID);
}
但是当我调用内容提供商时,两者都不匹配:
int uriType = sURIMatcher.match(uri);
switch (uriType) {
case SERVER_ID:
Log.d(TAG, "A server URI");
break;
case SERVER:
// no filter
Log.d(TAG, "All server URI");
break;
default:
Log.i(TAG, "Unknown URI on query: " + uri);
// throw new IllegalArgumentException("Unknown URI");
}
日志消息:
I/ServerContentProvider(442): Unknown URI on query: content://com.danny.servercontentprovider/server/1
当我尝试使用非数字uri时,我收到相同的错误消息(日志消息中没有“/ 1”)。
有什么想法吗?
答案 0 :(得分:1)
将AUTHORITY
的值更改为:
public static final String AUTHORITY = "com.danny.servercontentprovider";