另一个Android URI不匹配

时间:2012-12-01 15:57:48

标签: android pattern-matching uri

我有以下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”)。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

AUTHORITY的值更改为:

public static final String AUTHORITY = "com.danny.servercontentprovider";