Reputation: 521
I'd like the ability to add a contact to the user's contacts with a contact name (easy enough), a phone number, but also a custom label for that phone number as supported in ICS. For example, I might like to add "John Doe" with the phone number "xxx-xxx-xxxx" as custom type "Blackberry". Is this granularity possible?
Upvotes: 0
Views: 1845
Reputation: 1777
Try this code.
It is Custom add multiple record inside the one contact.
It's very easy for save contact detail application to default phone contact book.
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues row2 = new ContentValues();
row2.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
row2.put(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM);
row2.put(ContactsContract.CommonDataKinds.Email.LABEL, "Green Bot");
row2.put(ContactsContract.CommonDataKinds.Email.ADDRESS, "[email protected]");
data.add(row2);
ContentValues row3 = new ContentValues();
row3.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
row3.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM);
row3.put(ContactsContract.CommonDataKinds.Phone.LABEL, "Arpit");
row3.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "[email protected]");
data.add(row3);
Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "Jiks");
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "555-555-5555");
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
startActivity(intent);
Upvotes: 2
Reputation: 1020
This can be done with an Intent as seen below. (Bonus: You don't have to ask for read/write contacts permissions!) The specific fields you're interested in are ContactsContract.Intents.Insert.PHONE_TYPE and ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE
private void addContact(Activity activity)
{
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "John Smith");
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "555-555-5555");
intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, "Blackberry");
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, 555-444-3333);
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE, "School Phone");
activity.startActivity(Intent.createChooser(intent, ""));
}
Upvotes: 2