2

I'm trying to mimic the native behaviour of adding a phone number to an existing contact. The native behaviour has the following steps:

  1. Tapping on the "Add to a contact"/ "Update existing" opens the native contacts list Activity where the user has the option to choose a contact.

  2. Tapping on a contact opens the native edit contact activity and adds the selected phone number as an alternative phone number field (i.e. work).

Can I achieve this using an intent?

Similarly, I'm adding a contact using an intent. Here is my code:

Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.PHONE,phoneNumber);
intent.putExtra("finishActivityOnSaveCompleted", true);
dialog.dismiss();
context.startActivity(intent);
Bugs
  • 4,491
  • 9
  • 32
  • 41
android enthusiast
  • 2,062
  • 2
  • 24
  • 45
  • Try this https://stackoverflow.com/questions/22962365/add-new-contact-via-intent-with-multiple-phone-numbers https://stackoverflow.com/questions/14278587/insert-a-new-contact-intent – Anil Jul 04 '17 at 10:43
  • Possible duplicate of [Insert a new contact intent](https://stackoverflow.com/questions/14278587/insert-a-new-contact-intent) – Abdul Waheed Jul 04 '17 at 10:59
  • i think you need to use content provider for this – akshay_shahane Jul 04 '17 at 11:28
  • https://stackoverflow.com/questions/4179064/android-contact-info-update-with-intent – RonTLV Jul 04 '17 at 12:07
  • @RonTLV your solution worked. Please posted as an answer and I shall accept it. Thanks everyone for taking the time to post a potential solution. – android enthusiast Jul 04 '17 at 12:14

1 Answers1

4

this is the way to do it:

Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME, "TESTTEST");
i.putExtra(Insert.PHONE, "209384");
startActivity(i);
RonTLV
  • 2,376
  • 2
  • 24
  • 38