I have read the documentation on the Android ContentResolver
I have also searched for a suitable example to no avail.
According to the documentation, there is a method call
that can be used as a way to get access to custom provider methods when the standard content provider methods are insufficient:
final Bundle call(Uri uri, String method, String arg, Bundle extras)
Call a provider-defined method.
so in my code I execute:
getContentResolver().call(uri, method, arg, extras);
but it always returns null
bundle. In fact, the method in the provider never gets called.
Further research points to a (perceived) discrepancy of the contract where the RESOLVER has a uri argument with no equivalent PROVIDER parameter:
Bundle call(String method, String arg, Bundle extras)
Call a provider-defined method.
I am obviously not understanding something. Can anyone point me in the correct direction?
Further research points to a discrepancy of the contract where the RESOLVER has a uri argument with no equivalent PROVIDER parameter
That's the way they wrote it. The Uri
is simply to identify the ContentProvider
-- the ContentProvider
knows who it is and therefore does not need the Uri
.
the provider method does not allow @Override annotation
Yes, it does, as you can see in this sample ContentProvider
:
@Override
public Bundle call(String method, String arg, Bundle extras) {
if (SET_KEY_METHOD.equals(method) && arg != null) {
key=arg;
}
return(null);
}
However, your build target (e.g., in Eclipse, Project > Properties > Android) must be set to API Level 11 or higher.
The corresponding call()
from the client looks like:
getContentResolver().call(Provider.Constants.CONTENT_URI,
Provider.SET_KEY_METHOD, "sekrit", null);
Yes. I have a method in the provider that is declared 'public' that is passed into the contentresolver argument 'method.'
That's not how it works. call()
on ContentResolver
calls call()
on your ContentProvider
.
To answer your second question, my guess is that the ContentProvider
version of call()
does not need a Uri
argument because, unlike a ContentResolver
, it doesn't need to find a ContentProvider
; it calls the method on itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With