Reputation: 22637
android allows me to launch an intent to create a new contact. i can put extras into the intent to pre-fill the new contact fields.
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "Foo Bar");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "(408) 555-1212");
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
startActivityForResult(intent, INSERT_CONTACT_REQUEST);
this works, but i don't see how to handle multiple types of a given field, say phone number. in the intent, i can put extra a phone number, and i can put extra a phone number type, but how do i put extra an additional phone number, with a different (or perhaps even the same) type?
Upvotes: 5
Views: 4283
Reputation: 48871
ContactsContract.Intents.Insert
allows for PHONE, SECONDARY_PHONE and TERTIARY_PHONE
- the same applies for EMAIL
and it suggests three of each might be the maximum.
I don't know if it's possible to have more than one phone of the same 'type' - my phones contacts editor removes 'Home' from the list of choices once I've assigned a home number for example. You can, however, assign your own 'custom' type. For example, suppose your friend has two home numbers...
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "(123) 456-1212");
intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, "HOME-1");
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, "(123) 456-2121");
intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE, "HOME-2");
Upvotes: 6