9

I need to know if is it possible to join two or more contacts (in a programmatic way, using the Contacts android API or something).

For example, I have a contact "Axel Rose" with an email account and a phone number, and I've noticed that some apps like whatsapp, Facebook and Skype are creating new contact entries for Axel Rose, instead of merging the existing one.

I can join contacts using the "Join feature" from the phone, but is there a programmatic way?

Thanks in advance.
Cristian.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
cristianmiranda
  • 130
  • 2
  • 11
  • 3
    Yes this is doable, but seems too large of a coding answer to do for you. But you would need to find the contacts, grab all the information, delete the old ones and create a new one that is combined. I would start here: http://developer.android.com/reference/android/provider/ContactsContract.html – Michael Wildermuth Feb 28 '13 at 20:31
  • @MichaelWildermuth put that in as the answer please. Your telling him how to do it and that is exactly what he's asking for, code answers isn't always the best answer. – Warpzit Dec 02 '13 at 13:08
  • @crist Did you get any applicable solution for this.. – Ranjit Dec 10 '14 at 04:33

1 Answers1

1

You can use AggregationExceptions. See How to manual aggregate contacts ?

A good place to understand how contacts and aggregation works is Contacts Provider Documentation

Short summary:

The contacts that you see on your phonebook are the ones on the ContactsContract.Contacts table. The photo, phone, etc shown on the phonebook comes from different RawContacts entries. A contact can have one o several RawContacts.

A Contact happens to have several RawContact when the RawContacts share some data on common (name, phone number, email, etc). The union of this RawContacts into a single Contact is made by automatic aggregation rules (see Contact Basics docs).

You can't insert contacts on the ContactsContract.Contacts table. From the documentation:

Note: If you try to add a contact to the Contacts Provider with an insert(), you'll get an UnsupportedOperationException exception. If you try to update a column that's listed as "read-only," the update is ignored.

Juan M. Rivero
  • 807
  • 13
  • 18
  • 1
    I can't find the part on the docs you've shown, that talks about the merge/linking of contacts. Is there maybe a tutorial for this? I've noticed, for example that the newest contacts app of Google allows to link/merge multiple contacts. Is it open sourced? How does it work? Can you please show a sample code of merging/linking contacts? – android developer Feb 28 '17 at 15:36