Android Content Provider details 5

Source: Internet
Author: User

Contract type
The contract class defines constants, column names, intent actions that help the application use content URIs, and other contentprovider features. Contract classes are not automatically included by providers; provider developers must define them and then apply them to other developers. Many providers in the Android platform have corresponding contract classes in the android. provider package.

For example, the user dictionary Provider has a contract class UserDictionary, which contains the contentURI and columnname constants. The contentURI of the "words" table is defined on the constant UserDictionary. Words. CONTENT_URI. The UserDictionary. Words class also contains column name constants, which are used in the following code snippets. For example, a query projection can be defined as follows:

String [] mProjection =
{
UserDictionary. Words. _ ID,
UserDictionary. Words. WORD,
UserDictionary. Words. LOCALE
};

Another contract class is the ContactsContract class for the contact Provider. Such reference documents include sample code snippets. It is a subclass of ContactsContract. Intents. Insert. It is also a contract class and contains contracts for intent and intent data.

Reference MIME type
Contentprovider can return either a standard MIME type or a custom MIME type string, or both.

The MIME type has the following forms:

Type/subtype

For example, the MIME-type text/html that is widely known has the text type and the html subtype. If the provider returns this type from a URI, this indicates that the query for this URI will return text with HTML tags.

Custom MIME string, also called "vendor-specific" MIME type, has more complex types and child type values. The value of this type is always like this

Vnd. android. cursor. dir

Used for multiple rows, or

Vnd. android. cursor. item

Used for a single row.

The child type is different from each provider. Android built-in provider generally has a single word type. For example, when a Contact application creates a new line for a phone number, it sets the following MIME type for the new line:

Vnd. android. cursor. item/phone_v2

We can see that the child type value is just a simple phone_v2.

Other provider developers may create their own child types based on the authority of the provider and the table name. For example, if a provider contains a train schedule, the authority of the provider is com. example. trains, and it contains three tables: Line 1, line 2, and line 3. In the URI response,

Content: // com. example. trains/Line1

Pointing to line 1 table, provider returns the corresponding MIME type:

Vnd. android. cursor. dir/vnd. example. line1

Content URI

Content: // com. example. trains/Line2/5

Point to the 5th rows of the Line 2 table, and the corresponding MIME type returned by the provider is:

Vnd. android. cursor. item/vnd. example. line2

Most contentproviders define contract classes to contain the MIME types they use. For example, the contract class ContactsContract. RawContacts of the contact Provider defines the constant CONTENT_ITEM_TYPE, which corresponds to a row of original contact data.

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: info-contact@alibabacloud.com 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.