What is the mimeType attribute in <data> used for?

Any ContentProvider usually defines the type of data it handles (e.g. NotePadProvider handles a Notes data type defined in an inner class of NotePad). A MIME type is just a standardized way to define that data type by giving it a unique name. This allows the data type to be communicated to code that works with a ContentProvider in a standardized way.

It also helps a ContentProvider that handles several different types of data to keep things organized, e.g. a RailwayContentProvider might handle trains, stations and tickets and can use the MIME type to tell each one apart.

Why MIME types?

The use of MIME types is a natural consequence when you think about how a ContentProvider is accessed through URIs, i.e. something like an URL on the Internet. Just like on the Internet there are MIME types like text/html for web pages and image/jpeg for .jpg images, Android wants you to define a custom MIME type for any data type your ContentProvider handles.

An example custom MIME type

In the NotePad (linked above) class of the NotePad example project, you'll find:

public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.note";

This field defines a custom MIME type (recognizable by the type/subtype pattern).

Android suggests you use vnd.android.cursor.dir/... as the first part for any kind of "directory listing" (multiple items) and vnd.android.cursor.item/... as the first part for any kind of single item.

For the subtype, it's again suggested to start it with vnd. and then add something like your reverse domain name/package name, e.g. vnd.android.cursor.item/vnd.com.mydomain.myapp.mydata

To avoid all those vnd... strings in your code, there's also some constants in ContentResolver like CURSOR_DIR_BASE_TYPE and CURSOR_ITEM_BASE_TYPE.


Mimetype Multipurpose Internet Mail Extensions is tell you the description of the content

Text in character sets other than ASCII

Non-text attachments

Message bodies with multiple parts

Header information in non-ASCII character sets

and also whether is it Pdf/epub/html/text etc


If you mean mime type its to tell the receiving entity how to interpret a file. Just like you see .txt and know a file is a text file. This way you can serve a file with .anyExtension and have the browser still know it is a .txt