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?
Instead of accessing the Contacts Provider directly, an Intent starts the contacts app, which runs the appropriate Activity. For the modification actions described in this lesson, if you send extended data in the Intent it's entered into the UI of the Activity that is started.
To insert a new contact, use the ACTION_INSERT action, specify Contacts.CONTENT_TYPE as the MIME type, and include any known contact information in extras specified by constants in ContactsContract.Intents.Insert . None One or more of the extras defined in ContactsContract.Intents.Insert . Intent intent = new Intent ( Intent. ACTION_INSERT );
Finally, send the intent. In response, the contacts app displays an edit screen. When the user finishes editing and saves the edits, the contacts app displays a contact list. When the user clicks Back, your app is displayed. To edit a contact, call Intent (action) to create an intent with the action ACTION_EDIT.
To do this using an intent, create the intent using as much data as you have available, and then send the intent to the contacts app. Inserting a contact using the contacts app inserts a new raw contact into the Contacts Provider's ContactsContract.RawContacts table.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With