tags:

views:

1100

answers:

7

Hi,

Can you please tell me how to launch the Add Contact' activity in android? Thank you.

+2  A: 

This post may help you out or at least point you in the right direction.

Hope this helps.

Anthony Forloney
No. I am looking for how can I launch Android's Add Contact Activiy programmically. I tried both this and remove the commented code, both do not work.Intent intent = new Intent("android.intent.action.INSERT"); //intent.setType("vnd.android.cursor.item/person"); startActivity(intent);
hap497
A: 

I was looking through the Android source code and came up with this bit of code that I was sure would work:

String number = "123456789";
Intent addContactIntent = new Intent(Contacts.Intents.Insert.FULL_MODE);
addContactIntent.putExtra(Contacts.Intents.Insert.PHONE, number);
this.startActivity(addContactIntent);

But it doesn't work, I get a Force Close error that says nothing was found to handle the intent.

Would love to know if anyone has found the answer to this.

mbaird
+1  A: 

This should be the snippet your are looking for:

Intent addContactIntent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
addContactIntent.putExtra(Contacts.Intents.Insert.NAME, "Jean-Claude"); // an example, there is other data available
startActivity(addContactIntent)
Gautier Hayoun
+2  A: 

I was also trying to do this. I was able to launch the activity using Android 2.2. I haven't tried using/testing this in other SDK versions though.

Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse("tel:" + currentNum.getText())); //currentNum is my TextView, you can replace it with the number directly such as Uri.parse("tel:1293827")
intent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true); //skips the dialog box that asks the user to confirm creation of contacts
startActivity(intent);

Hope this might help.

Zarah
A: 

Thanks Gautier Hayoun

I Run you code and it is work but the phonebook will be opened. How can i hide it.

Yassar
A: 

Hey this is to add name to the contacts but how do i add a phone number to this name("Jean-Claude")..???can u plz help.

Thanks in ADV:)

Jyothi Attaluri
+1  A: 

API Level 5 and above solution

// Add listener so your activity gets called back upon completion of action,
// in this case with ability to get handle to newly added contact
myActivity.addActivityListener(someActivityListener);

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);

// Just two examples of information you can send to pre-fill out data for the
// user.  See android.provider.ContactsContract.Intents.Insert for the complete
// list.
intent.putExtra(ContactsContract.Intents.Insert.NAME, "some Contact Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "some Phone Number");

// Send with it a unique request code, so when you get called back, you can
// check to make sure it is from the intent you launched (ideally should be
// some public static final so receiver can check against it)
int PICK_CONTACT = 100;
myActivity.startActivityForResult(intent, PICK_CONTACT);
zwickilton