views:

31

answers:

1

I'm trying to implement a database in my application. I'm following a tutorial about writing my own ContentProvider, but I'm confused about SQLiteOpenHelper::getType. We're supposed to write it and, essentially, write a switch that returns the MIME type corresponding to the type of data we're dealing with.

I don't fully understand it. I'm not sure, even though I have an example, what is precisely supposed to be conveyed here. How do I determine the MIME type of my different tables of data? Could someone give me a good explanation of this?

tutorial

A: 

I'm trying to implement a database in my application.

This has nothing to do with ContentProvider. A ContentProvider does not need to use a database; a database does not need to be hidden by a ContentProvider.

I'm following a tutorial about writing my own ContentProvider, but I'm confused about SQLiteOpenHelper::getType.

There is no getType() method on SQLiteOpenHelper. I am going to assume you are referring to getType() on ContentProvider.

what is precisely supposed to be conveyed here

Um...a MIME type.

How do I determine the MIME type of my different tables of data?

For a database, you probably invent your own MIME types. Bear in mind that ContentProvider is not only used for a table-style structure -- it can be used for returning files as well. In this case, you'd try to use the MIME types appropriate to the file in question.

Could someone give me a good explanation of this?

You are presumably viewing this Web page in a Web browser. When you clicked the link or whatever that led you here, your Web browser made an HTTP request to the Web server, providing a URI of /questions/3559053/could-someone-explain-sqliteopenhelper-gettype. The StackOverflow Web server returned the content of the page, along with the MIME type of the content itself. This latter piece is important, particularly for this URI, since there is no file extension. Without a MIME type, the Web browser would not know what to do with the results of the HTTP request.

Android follows the same model.

For example, you can create an ACTION_VIEW Intent for a Uri representing a contact in the ContactsContract ContentProvider. However, if there were no way for Android to figure out a MIME type, you could not start an activity using the Intent. Android needs to ask the ContentProvider, "yo, dawg, U gots me a MIME type fo' this Uri?". Then, armed with an action (ACTION_VIEW) and a MIME type, Android can find a matching activity that can process the request.

CommonsWare