Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert contact intent, multiple phone / email / etc types?

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?

like image 477
Jeffrey Blattman Avatar asked Jan 04 '11 23:01

Jeffrey Blattman


People also ask

How do intents work with contacts?

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.

How do I insert a new contact in MIME type?

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 );

How do I edit a contact using an intent?

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.

How do I insert a raw contact using an intent?

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.


1 Answers

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");
like image 77
Squonk Avatar answered Nov 09 '22 00:11

Squonk