我有以下 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);
}
但是当我调用内容提供者时,两个 uri 都不匹配:
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”)。
有任何想法吗?