开发者

Can't access content provider of another application (android)

I have created a custom content provider in application A and have another application B access this content provider in A. Below are my code snippets:

In content provider in application A:

public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    int table = um.match(uri);
    SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();;

    // configure where to query from
    if (table == MYKEYS || table == MYKEY_ID) {
        sqlBuilder.setTables(DATABASE_TABLE_MY);
        if (table == MYKEY_ID)
            sqlBuilder.appendWhere(
            _ID + " = " + uri.getPathSegments().get(1)); 
    }

    else if (table == FDKEYS || table == FDKEY_ID) {
        sqlBuilder.setTables(DATABASE_TABLE_FD);
        if (table == FDKEY_ID)
            sqlBuilder.appendWhere(
            _ID + " = " + uri.getPathSegments().get(1));
    }

    else 
        throw new IllegalArgumentException("Unknown URI: " + uri);

    if (sortOrder==null || sortOrder=="")
        sortOrder = DEFAULT_SORT_ORDER;

    // query
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
    Cursor c = sqlBuilder.query(
               db, 
               projection, 
               selection, 
               selectionArgs, 
               null, 
               null, 
               sortOrder);

    //register to watch a content URI for changes
    c.setNotificationUri(getContext().getContentResolv er(), uri);

    return c;
}

This is how I declare my content provider in application A manifest file:

<provider android:name=".KeysProvider"
android:authorities="com.android.keychain.keysprovider"/>

This is how I make a query in application B:

String[] whereArgs = new String[]{"Private Key"};
Cursor c = managedQuery(MYTABLE_URI, null, "name", whereArgs, null); 

When I run the the code for application B, I have the following errors:

07-02 12:53:58.153: ERROR/DatabaseUtils(9195): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x126558

I really don't know what's wrong here. It works fine when I tried to access this same content provider from within application A. Also, looking from the log, it seems that from application B (at managedQuery lin开发者_StackOverflowe), it is able to go to this content provider in application A (KeysProvider) but dies when trying to make a query (at line: Cursor c = sqlBuilder.query ... ). Anyone knows what's the problem here?

Thanks very much in advance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜