1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
private void addContact(){
createNewClient();
ContentValues personValues = new ContentValues();
personValues.put(Contacts.People.NAME, "john doe");
/* STARRED 0 = Contacts, 1 = Favorites */
personValues.put(Contacts.People.STARRED, 1);
Uri newPersonUri = getContentResolver().insert(Contacts.People.CONTENT_URI, personValues);
if (newPersonUri != null) {
//add phone number
ContentValues mobileValues = new ContentValues();
Uri mobileUri = Uri.withAppendedPath(newPersonUri,Contacts.People.Phones.CONTENT_DIRECTORY);
mobileValues.put(Contacts.Phones.NUMBER,"+33654777777");
mobileValues.put(Contacts.Phones.TYPE,Contacts.Phones.TYPE_MOBILE);
Uri phoneUpdate = getContentResolver().insert(mobileUri, mobileValues);
// add email
ContentValues emailValues = new ContentValues();
Uri emailUri = Uri.withAppendedPath(newPersonUri,Contacts.People.ContactMethods.CONTENT_DIRECTORY);
emailValues.put(Contacts.ContactMethods.KIND,Contacts.KIND_EMAIL);
emailValues.put(Contacts.ContactMethods.TYPE,Contacts.ContactMethods.TYPE_HOME);
emailValues.put(Contacts.ContactMethods.DATA,"john.doe@mail.com");
Uri emailUpdate = getContentResolver().insert(emailUri, emailValues);
}
Toast.makeText(this, "contact added", Toast.LENGTH_LONG).show();
} |
Partager