Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically join 2 contacts in android?

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.

like image 738
cristianmiranda Avatar asked Aug 15 '12 01:08

cristianmiranda


People also ask

How do I link two contacts on Android?

Open your device's Contacts app . At the top right, tap More Select. Choose the contacts you want to merge. At the top right, tap More Merge.

How can merge duplicate contacts in Android programmatically?

Access your Contacts app and tap on the menu button. From the menu, tap on “Merge accounts” and from next prompt tap on “Merge from Google”. From the next prompt, tap on “OK” and all your contacts will be merged. This will merge the accounts to get rid of duplicate contacts that were created due to multiple accounts.

How do I merge two contacts together?

Step 1: Go to the Contacts app on your phone and click on the menu button. Step 2: From the top right corner of the screen, tap on 'Settings', then on 'Contact Manager' and then on 'Merge Contacts'. Step 3: Now, if you want to merge any particular duplicate contact suggestion, select that contact and tap on 'Merge'.


1 Answers

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.

like image 198
Juan M. Rivero Avatar answered Oct 04 '22 15:10

Juan M. Rivero