.update () ContentProvider throws Unknown Uri while .query () works?

Appendix A with the following content AndroidManifest.xml

(name and authority edited)

<provider
     android:name="test.provider"
     android:authorities="test.content_authority"
     android:exported="true" />

      

With the following ContentProvider class:

public class Provider extends ContentProvider {
    @Override
    public int update(Uri uri, ContentValues values, String selection, 
                      String[] selectionArgs) { 
        // [...]
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, 
                        String[] selectionArgs, String sortOrder) {
        // [...]
    }
}

      

From another app B I have no problem requesting this provider:

String URL = "content://test.content_authority/data";
Uri data = Uri.parse(URL);
Cursor c = getContentResolver().query(data, null, null, null, null);

      

But when I try to update

record:

String URL = "content://test.content_authority/data";
Uri favarticles = Uri.parse(URL);
ContentValues values = new ContentValues();
values.put("key", "value");
getContentResolver().update(favarticles, values, null, null);

      

I am getting the following exception:

java.lang.UnsupportedOperationException: Unknown Uri: content://test.content_authority/data
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.update(ContentProviderNative.java:560)
    at android.content.ContentResolver.update(ContentResolver.java:1316)
    at com.example.test_contentprovider.MainActivity.updateEntryTest(MainActivity.java:119)

      

Is there something clearly wrong? I do not have permission to access the Provider? Why am I getting an exception Unknown Uri

when I can access this URI using query

?

Thank you very much.

+3


source to share





All Articles