tags:

views:

202

answers:

1

Hi, I am having trouble understanding content providers in Android.

Do you use intents to call content providers as well as managed queries?

Also, an activity has an intent filter. The intent filter has a element which has a mimeType attribute. How does Android know which content provider this mimetype is referring to?
The tag in the manifest just lists an authority but not the full content_uri. Further, the content_uri is typically defined in an encapsulated class that seems to only consist of constants but no methods, so I don't see how that links over to the content provider class.

Thanks

+2  A: 

I answered some of these questions earlier today on android-developers. Let me try it again here.

Do you use intents to call content providers as well as managed queries?

No.

How does Android know which content provider this mimetype is referring to?

It asks the ContentProvider, via getType(), to provide the MIME type for the Uri that is in the Intent.

The tag in the manifest just lists an authority but not the full content_uri.

That is all that is needed for Android to find the right ContentProvider on which to call getType().

CommonsWare
private void pickMe() { Intent i = new Intent(Intent.ACTION_PICK); i.setType(River.CONTENT_TYPE); i.setData(River.CONTENT_URI); startActivityForResult(i, PICK_ME); }CONTENT_URI is the same thing as "content://com.river.provider.Pickme/pickmeProvider" which is a content provider.So is the activity using the intent i to call a content provider? The URI in setData() resolves to a content provider? But that can't be right b/c intents don't call content providers, but that's what it looks like to me. This is what I'm not understanding.
Hugh
"So is the activity using the intent i to call a content provider?" No. The `Activity` is using the `Intent` to start another `Activity`. That second `Activity` is probably getting its data from the `ContentProvider`, but the details of that are up to the implementation of that second `Activity`.
CommonsWare