Using resources content providers and intents

The primary registered content types are application audio example image message model multipart text video

Each of these primary types has subtypes. But if a vendor has proprietary data formats, the subtype name begins with vnd. For example, Microsoft Excel spreadsheets are identified by the subtype vnd.ms-excel, whereas pdf is considered a nonvendor standard and is represented as such without any vendor-specific prefix.

Some subtypes start with x-; these are nonstandard subtypes that don't have to be registered. They're considered private values that are bilaterally defined between two collaborating agents. Here are a few examples:

application/x-tar audio/x-aiff video/x-msvideo

Android follows a similar convention to define MIME types. The vnd in Android MIME types indicates that these types and subtypes are nonstandard, vendor-specific forms. To provide uniqueness, Android further demarcates the types and subtypes with multiple parts similar to a domain spec. Furthermore, the Android MIME type for each content type has two forms: one for a specific record, and one for multiple records.

For a single record, the MIME type looks like this:

vnd.android.cursor.item/vnd.yourcompanyname.contenttype

For a collection of records or rows, the MIME type looks like this: vnd.android.cursor.dir/vnd.yourcompanyname.contenttype

Here are a couple examples: //One single note vnd.android.cursor.item/vnd.google.note

//A collection or a directory of notes vnd.android.cursor.dir/vnd.google.note

MIME types are extensively used in Android, especially in intents, where the system figures out what activity to invoke based on the MIME type of data. MIME types are invariably derived from their URIs through content providers. You need to keep three things in mind when you work with MIME types:

• The type and subtype need to be unique for what they represent.

• As mentioned earlier, they need to be preceded with vnd if they are not standard (which is usually the case when you talk about specific records).

• They are typically namespaced for your specific need.

You should also note that the primary MIME type for a collection of items returned through an Android cursor should always be vnd.android.cursor.dir, and the primary MIME type of a single item retrieved through an Android cursor should be vnd.android.cursor.item. You have more wiggle room when it comes to the subtype, as in vnd.google.note; after the vnd. part, you are free to subtype it with anything you'd like.

0 0

Post a comment