Android handout 9: Batch insert to phone book

Source: Internet
Author: User

Contentvalues values = new contentvalues ();

// First, execute a null value insert to rawcontacts. content_uri to obtain rawcontactid returned by the system.
Uri rawcontacturi = context. getcontentresolver (). insert (rawcontacts. content_uri, values );
Long rawcontactid = contenturis. parseid (rawcontacturi );
Values. Clear ();
Values. Put (data. raw_contact_id, rawcontactid );
// Set the content type
Values. Put (data. mimetype, structuredname. content_item_type );
// Set the contact name
Values. Put (structuredname. given_name, result_name );
// Add a contact name to the contact URI
Getcontentresolver (). insert (
Android. provider. contactscontract. Data. content_uri, values );

Values. Clear ();
Values. Put (data. raw_contact_id, rawcontactid );
Values. Put (data. mimetype, phone. content_item_type );
// Set the contact's phone number
Values. Put (phone. Number, result_phone );
// Set the phone type
Values. Put (phone. type, phone. type_mobile );
// Add a phone number to the contact phone number URI
Context. getcontentresolver (). insert (
Android. provider. contactscontract. Data. content_uri, values );

Values. Clear ();
Values. Put (data. raw_contact_id, rawcontactid );
Values. Put (data. mimetype, email. content_item_type );
// Set the contact's email address
Values. Put (email. Data, result_email );
// Set the email type
Values. Put (email. type, email. type_work );
// Add email data to the contact email URI
Context. getcontentresolver (). insert (
Android. provider. contactscontract. Data. content_uri, values );

Values. Clear ();
Values. Put (data. raw_contact_id, rawcontactid );
Values. Put (data. mimetype, organization. content_item_type );
// Set the contact's company address
Values. Put (organization. Data, result_address );
// Set the company address type
Values. Put (organization. type, organization. type_work );
// Add company address data to the contact company address URI
Context. getcontentresolver (). insert (
Android. provider. contactscontract. Data. content_uri, values );

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.