Use ContentProvider to manage contacts------Add contacts

Source: Internet
Author: User

Add.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
Get three text boxes in the program interface
String name = ((EditText) Findviewbyid (R.id.name)). GetText (). toString ();
String phone = ((EditText) Findviewbyid (R.id.phone)). GetText (). toString ();
String email = ((EditText) Findviewbyid (R.id.email)). GetText (). toString ();
Create an empty Contentvalues
Contentvalues values = new Contentvalues ();
Perform a control insert to the Rawcontacts.content_uri
The goal is to get the Rawcontactid returned by the system
Uri Rawcontacturi = Getcontentresolver (). Insert (Rawcontacts.content_uri, values);
Long Rawcontactid = Contenturis.parseid (Rawcontacturi);
Values.clear ();
Values.put (data.raw_contact_id, Rawcontactid);
Set Content Type
Values.put (Data.mimetype, Structuredname.content_item_type);
Set Contact name
Values.put (Structuredname.given_name,name);
Add contact name to 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 phone number of the contact person
Values.put (Phone.number, Phone);
Set up phone type
Values.put (Phone.type, phone.type_mobile);
Add a phone number to a contact phone number URI
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 E_Mail address of a contact
Values.put (Email.data, Email);
Set the type of the e-mail message
Values.put (Email.type, email.type_work);
Add e-mail data to a contact E_Mail URI
Getcontentresolver (). Insert (
Android.provider.ContactsContract.Data.CONTENT_URI, values);
Toast.maketext (mainactivity.this, "contact data added successfully", 8000). Show ();
}
});

Use ContentProvider to manage contacts------Add contacts

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.