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 );