Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CONTENT TYPE - Is vnd.android.cursor.dir some standard constant defined by android?

Tags:

android

I have very basic understanding problem of Content types.

I went through lot of examples and text explaining the above term, but still have some basic understanding problem. Can some clarify me please.

In the android notepad example, and many others, it is mentioned vnd.android.cursor.dir/ resolves to a list of items in a directory and vnd.android.cursor.item/ refers to specific item in a directory.

Is this vnd.android.cursor.dir some standard constant defined by android. Where did this come from?, or can i change it like

vn.com.android.myexample.dir/

How is this even resolved and what is its purpose, why not use the full CONTENT_URI?

Sorry, i'm totally lost, and don't understand this.

like image 689
devgp Avatar asked Sep 26 '11 23:09

devgp


People also ask

What is a cursor in Android?

Cursors are what contain the result set of a query made against a database in Android. The Cursor class has an API that allows an app to read (in a type-safe manner) the columns that were returned from the query as well as iterate over the rows of the result set.

What is content resolver in Android?

The ContentResolver methods provide the basic "CRUD" (create, retrieve, update, and delete) functions of persistent storage. A common pattern for accessing a ContentProvider from your UI uses a CursorLoader to run an asynchronous query in the background.


2 Answers

Documentation: https://developer.android.com/guide/topics/providers/content-provider-basics#MIMETypeReference

The MIME types returned by ContentProvider.getType have two distinct parts:

type/subType 

The type portion indicates the well known type that is returned for a given URI by the ContentProvider, as the query methods can only return Cursors the type should always be:

  • vnd.android.cursor.dir for when you expect the Cursor to contain 0 through infinity items

or

  • vnd.android.cursor.item for when you expect the Cursor to contain 1 item

The subType portion can be either a well known subtype or something unique to your application.

So when using a ContentProvider you can customize the second subType portion of the MIME type, but not the first portion. e.g a valid MIME type for your apps ContentProvider could be:

vnd.android.cursor.dir/vnd.myexample.whatever 

The MIME type returned from a ContentProvider can be used by an Intent to determine which activity to launch to handle the data retrieved from a given URI.

like image 60
Rob Avatar answered Oct 09 '22 00:10

Rob


Where did this come from?, or can I change it like vn.com.android.myexample.dir/

No, because "vnd" stands for vendor in MIME Registration trees, android in this case.

like image 42
Andrew Avatar answered Oct 08 '22 23:10

Andrew