Can't access content provider of another application


Last Updated:

  1. maryandbob

    maryandbob New Member This Topic's Starter

    Joined:
    Jul 2, 2010
    Messages:
    1
    Likes Received:
    0
    Hi,

    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().getContentResolver(), 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
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:190)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:55)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1221)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:316)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:266)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at com.android.keychain.KeysProvider.query(KeysProvider.java:233)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:117)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:98)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at android.os.Binder.execTransact(Binder.java:287)
    07-02 12:53:58.153: ERROR/DatabaseUtils(9195): at dalvik.system.NativeStart.run(Native Method)
    07-02 12:53:58.161: DEBUG/AndroidRuntime(9434): Shutting down VM
    07-02 12:53:58.161: WARN/dalvikvm(9434): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
    07-02 12:53:58.161: ERROR/AndroidRuntime(9434): Uncaught handler: thread main exiting due to uncaught exception
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x126558
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:326)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.content.ContentProviderProxy.query(ContentProviderNative.java:345)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.content.ContentResolver.query(ContentResolver.java:202)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.app.Activity.managedQuery(Activity.java:1495)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at com.android.verifyfbrequest.SignedId$idRequestListener$1.run(SignedId.java:123)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.os.Handler.handleCallback(Handler.java:587)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.os.Handler.dispatchMessage(Handler.java:92)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.os.Looper.loop(Looper.java:123)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at android.app.ActivityThread.main(ActivityThread.java:4363)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at java.lang.reflect.Method.invokeNative(Native Method)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at java.lang.reflect.Method.invoke(Method.java:521)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    07-02 12:53:58.169: ERROR/AndroidRuntime(9434): at dalvik.system.NativeStart.main(Native Method)

    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 line), 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
     

    Advertisement

Share This Page

Loading...