对内容提供商的URI匹配无法正确匹配 [英] URI Matching on content provider not matching correctly

查看:181
本文介绍了对内容提供商的URI匹配无法正确匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,现在一段时间,但我似乎无法化解我的URI的匹配问题。任何帮助是极大的AP preciated。

I've been trying now for a while but I can't seem to resolve my URI matching problem. Any help is greatly appreciated.

下面是我的声明内容URI和URI匹配:

Here is my declaration of the content uri and the 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);
}

和传递是在池莉构建以下code中的URI:

And the uri being passed is contructed in the following code:

    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,因为它涉及的参数,但它永远不会匹配。

I debug the method and I am able to see the URI as it comes in the parameter, but it never matches.

如何在URI来了:

content://edu.uprm.civil.db/get-table/q?table=150

如果您需要任何更多的信息,请让我知道,它是一个头疼的问题我...

If you need any more info please let me know, it's been a headache for me...

推荐答案

修改规则,为你的 UriMatcher ,然后取出启动 / 从路径参数:

Modify the rules for your UriMatcher and remove the starting / from the path parameter:

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匹配无法正确匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆