Next, Some Typing
Next you need to come up with some MIME types corresponding with the content from your content provider.
Android uses both the content Uri and the MIME type as ways to identify content on the device. A collection content – or, more accurately, the combination authority and data type path – should map to a pair of MIME types. One MIME type will represent the collection; the other will represent an instance. These map to the patterns discussed in the previous section for no‑identifier and identifier cases, respectively. As you saw in Chapters 24 and 25, you can fill a MIME type into an to route the to the proper activity (e.g., on a collection MIME type to call up a selection activity to pick an instance out of that collection).
The collection MIME type should be of the form , where is the name of your firm, organization, or project, and is a dot‑delimited type name. So, for example, you might use as the MIME type for your collection of secrets.
The instance MIME type should be of the form , usually for the same values of and as you used for the collection MIME type (though that is not strictly required).
Step #1: Create a Provider Class
Just as an activity and intent receiver are both Java classes, so is a content provider. So, the big step in creating a content provider is crafting its Java class, with a base class of .
In your subclass of , you are responsible for implementing six methods that, when combined, perform the services that a content provider is supposed to offer to activities wishing to create, read, update, or delete content.
Дата добавления: 2015-05-16; просмотров: 710;