Android content providers-create content providers (implementing the MIME type of contentprovider)

Source: Internet
Author: User

The contentprovider class has two methods that can return the MIME type:

GetType ()

You must provide one of the necessary methods for implementation.

Getstreamtypes ()

If your provider provides files, you are expected to implement this method.

Mime Type for tables

The GetType () method returns a string in the MIME format that describes the data type returned by the content resource identifier (URI) parameter. This URI is modeled rather than a specific URI; therefore, you should return the data type associated with the content resource identifier that matches this pattern.

For common data types such as text, HTML, and JPEG, The GetType () method should return the standard MIME data type. These standard valid MIME types are listed on the iana_mime_media_types website (

For the content resource identifier (URI) that points to one or more rows of table data, the GetType () method should return a MIME type in the MIME format specified by the following Android vendor:

1. Type part: VND

2. Child type:

If the resource identification (URI) mode is for a single row of data, use: Android. crusor. Item/

If the resource identification (URI) mode is for multi-row data, use: Android. cursor. DIR/

3. Specify the providers' part: VND. <Name> <type>

You must provide <Name> and <type>. The value of <Name> must be globally unique, and the value of <type> must be unique relative to the URI mode. It is a good choice for <Name> using your company name or the android package name of your application. For <type> using the string of the identifier table associated with Uri is a good choice.

For example, if a provider has the permission of COM. example. App. provider and the table to be exposed is named Table1, the MIME type of multiple rows in Table1 is:

Vnd. Android. cursor. DIR/ example. provider. Table1

The MIME type of a single row in Table1 is:

Vnd. Android. cursor. Item/ example. provider. Table1

Object MIME type

If you provide files, you need to implement the getstreamtypes () method. This method returns an array of mime-type strings for files. This array contains the file types that your provider can return to the file marked by the content resource. You should use the MIME type filter parameters to filter the MIME types you provide so that only the MIME types that the client wants to process are returned.

For example, if an app calls the contentresolver that contains the "image/*" (image in any format) filter string, a file in the format of .jpg, .png, and GIF is provided. getstreamtypes () method, then contentprovider. the getstreamtypes () method should return the following array:

{"Image/JPEG", "image/PNG", "image/GIF "}

If the application is only interested in .jpg files, call the * \/JPEG contentresolver. getstreamtypes () method with a filter string and the contentprovider. getstreamtypes () method with the following results:

{"Image/JPEG "}

If your provision does not provide the MIME type requested by the filter string, the getstreamtypes () method should return null.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.