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