Android content providers (3) -- contacts provider

Source: Internet
Author: User

Next, go to the android content providers (II) -- contacts provider to continue. Next, we will describe the top-level contacts, the contacts is the aggregate contact table, and the rawcontacts discussed earlier is the original contact table, in the architecture of the android address book, there are three layers: Aggregation contacts, original contacts, and data tables. Data Tables mainly store data and the ID associated with the original contact. The field data of the data table has been described before, and the original contact rawcontacts does not directly store data, data is stored in the data table through ID Association. For aggregate contacts, here we will first talk about accounts in Android. Android can bind multiple accounts, there can be a contact information under each account, but when we enter the address book, what we see is aggregate contacts. If we have multiple accounts, each account has the same contact, we do not want to see that the same contact appears multiple times. All the tables with the aggregated contact have the same contacts, and the contacts are also associated with the original contact table by ID. Let's take a look at the relationship between the three:


The top layer displays the aggregate contact table contacts, with the original contact table rawcontacts in the middle. Three accounts (two Gmail accounts and one Twitter account) store the contact information respectively, the bottom layer is the data table, which stores the contact information. The figure shows the three-tier architecture of the address book of the Android system.

During use, you can use intent to modify the address book. The following table shows several ways to directly call the copper Cortana system:

Task

Action

Data

Mime Type

Notes

Pick a contact from a list

Action_pick

One:

  • Contacts. content_uri, Which displays a list of contacts.
  • Phone. content_uri, Which displays a list of phone numbers
    For a raw contact.
  • Structuredpostal. content_uri, Which displays
    List of postal addresses for a raw contact.
  • Email. content_uri, Which displays a list of email addresses
    For a raw contact.

Not used

Displays a list of raw contacts or a list of data from a raw contact, depending on the content URI type you supply.

CallStartactivityforresult (), Which returns the content URI of the selected
Row. The form of the URI is the table's content URI with the row'sLookup_idAppended to it. The device's contacts app delegates read and write permissions to this content URI for the life of your activity. See the content
Provider basics guide for more details.

Insert a new raw contact

Insert. Action

N/

Rawcontacts. content_type, MIME type for a set of raw contacts.

Displays the device's contacts application'sAdd contactScreen. The extras values you add to the intent are displayed. If sentStartactivityforresult (),
The content URI of the newly-added raw contact is passed back to your activity'sOnactivityresult ()Callback
Method inIntentArgument, in the "data" field. To get the value, callGetdata ().

Edit a contact

Action_edit

Content_lookup_uriFor the contact. The editor activity will allow the user to edit
Any of the data associated with this contact.

Contacts. content_item_type, A single contact.

Displays the edit Contact Screen in the contacts application. The extras values you add to the intent are displayed. When the user clicksDoneTo save the edits, your activity returns to the foreground.

Here we provide a method to use intent, and other usage methods. The specific usage is as follows:

// Gets values from the UI

String name = mcontactnameedittext. gettext (). tostring ();

String phone = mcontactphoneedittext. gettext (). tostring ();

String email = mcontactemailedittext. gettext (). tostring ();

String Company = mcompanyname. gettext (). tostring ();

String jobtitle = mjobtitle. gettext (). tostring ();

// Creates a new intent for sending to the device's contacts Application

Intent insertintent = newintent (contactscontract. intents. Insert. action );

// Sets the MIME type to the one expected by the insertion activity

Insertintent. settype (contactscontract. rawcontacts. content_type );

// Sets the new contact name

Insertintent. putextra (contactscontract. intents. Insert. Name,
Name );

// Sets the new company and job title

Insertintent. putextra (contactscontract. intents. Insert. Company,
Company );

Insertintent. putextra (contactscontract. intents. Insert. job_title,
Jobtitle );

Finally, you need to add two permissions when using the system contact:

<Uses-Permission Android: Name = "android. Permission. read_contacts">

<Uses-Permission Android: Name = "android. Permission. write_contacts">

For more information, see: http://developer.android.com/guide/topics/providers/contacts-provider.html

I still have some understanding about this part, but I will continue to study it later. Interested friends can study it together.

To join our QQ group or public account, see: Ryan's
Zone public account and QQ Group


Welcome to my Sina Weibo chat: @ Tang Ren _ Ryan

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: 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.