How can I launch the 'Add Contact' activity in android
Asked Answered
E

8

38

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

Emileeemili answered 13/12, 2009 at 0:42 Comment(0)
T
10

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

Hope this helps.

Update 05/11/2015:

Per the comments, check out vickey's answer below for the appropriate solution.

Trihedral answered 13/12, 2009 at 1:34 Comment(3)
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);Emileeemili
This answer is really old, here is the correct code as mentioned below: Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); startActivity(intent);Sot
doesn't look like an answer. You can't just answer with the links to other answers.Vain
V
61

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);
Vigilant answered 28/9, 2010 at 19:54 Comment(4)
This almost works for me but my onActivityResult method is not being called (the first line in this response was omitted because there is no method addActivityListener as far as I can tell)Carlita
how does one get back the name and number added from the returned intent in onActivityResult?Depressive
I prefere to use ACTION_INSERT_OR_EDIT instead of ACTION_INSERTIrrelevance
Just change ACTION_INSERT with ACTION_INSERT_OR_EDIT in the previous source codeIrrelevance
G
46

These two lines do the trick:

    Intent intent = new Intent(Intent.ACTION_INSERT, 
                               ContactsContract.Contacts.CONTENT_URI);
    startActivity(intent);
Guajardo answered 26/7, 2012 at 6:24 Comment(1)
lol, I dont know why this is not the accepted answer. This is all you need really.Sot
C
16

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)
Calgary answered 13/1, 2010 at 18:15 Comment(0)
T
10

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

Hope this helps.

Update 05/11/2015:

Per the comments, check out vickey's answer below for the appropriate solution.

Trihedral answered 13/12, 2009 at 1:34 Comment(3)
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);Emileeemili
This answer is really old, here is the correct code as mentioned below: Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); startActivity(intent);Sot
doesn't look like an answer. You can't just answer with the links to other answers.Vain
S
10

If you have a phone no and want to save it in your own application then use this code it will move you to the "create contact" page of the default contact app.

  Intent addContactIntent = new Intent(Intent.ACTION_INSERT);
  addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
  addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,phnno.getText().toString());
  startActivity(addContactIntent);
Solvable answered 13/10, 2012 at 16:51 Comment(0)
M
8

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.

Multinational answered 19/7, 2010 at 7:23 Comment(1)
I try this code but it`s did not skip confirm dialog box !Adoration
M
5

If you need to add a phone number to an existing contact or create a new one (just as the native dialer does with a new phone number) this code might be just what you need:

final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(Insert.PHONE, digits);
intent.setType(People.CONTENT_ITEM_TYPE);
startActivity(intent);

Just take a look at the Android's source code for the DialpadFragment class, search for the method getAddToContactIntent(String digits).

But as the People class is deprecated in api 10 you may want to use this line instead:

intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
Monsignor answered 4/10, 2012 at 8:9 Comment(0)
S
1
Intent localintent = new Intent("android.intent.action.INSERT",ContactsContract.Contacts.CONTENT_URI);
localintent.putExtra("phone", phoneNumber);
startActivity(localintent);
Soukup answered 19/11, 2014 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.