I really can’t get the meaning of mimeType. I know that it exists so that the getType
method in ContentProvider
knows what to match with it. But I’m still not sure what it means or how it’s used.

- 3,952
- 6
- 38
- 55

- 5,928
- 9
- 52
- 80
-
@Randroid If there was a downvote for comments....... – HB. Jul 20 '18 at 09:59
3 Answers
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.

- 274
- 3
- 12

- 20,771
- 6
- 58
- 65
-
4I highly recommend the [NotePad example project](http://developer.android.com/resources/samples/NotePad/index.html) if you want to write your own `ContentProvider` (posting as comment due to link limit in answer). – Philipp Reichart Aug 23 '11 at 10:43
-
Wonderful answer!!!! So we can put anything we like behind "vnd.android.cursor.dir/",right?Or it has some constraint that must be follow to avoid conflict with exist mimeTypes? – Frank Cheng Aug 23 '11 at 11:21
-
2The Android docs suggest you also start the subtype (after the `/`) with `vnd.` to mark it as "custom MIME subtype" [see: What is the meaning of "vnd" in MIME types?](http://stackoverflow.com/questions/5351093/what-is-the-meaning-of-vnd-in-mime-types) -- after that just use reverse-domain notation (i.e. Java package names) to get a unique name. See the last the last paragraph of my answers for an example :) – Philipp Reichart Aug 23 '11 at 11:32
-
To avoid all those `vnd...` strings in your code, there's also some constants in `ContentResolver` like [CURSOR_DIR_BASE_TYPE](http://developer.android.com/reference/android/content/ContentResolver.html#CURSOR_DIR_BASE_TYPE) and [CURSOR_ITEM_BASE_TYPE](http://developer.android.com/reference/android/content/ContentResolver.html#CURSOR_ITEM_BASE_TYPE). – Philipp Reichart Aug 23 '11 at 11:41
-
2@Philipp Reichart : great answer, thanks, it should be as clear as you answer in the doc! – Paul Dec 27 '11 at 08:53
-
if anyone is still unclear on this i highly recommend this article : http://www.grokkingandroid.com/android-tutorial-content-provider-basics/ – Petrov May 15 '13 at 10:50
-
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

- 41,633
- 14
- 96
- 115
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

- 24,551
- 17
- 53
- 78