Ways to merge contacts

Ways to merge contacts.

I. How to read contacts from your address book:
<<Starting Starting from Android 2.0 (API Level 5), the Android platform provides an improved Contacts API for managing and integrating contacts from other data sources like VCard, Facebook, Orkut, Yahoo, Google account. To handle overlapping data from multiple sources, the contacts content provider aggregates similar contacts and presents them to users as a single entity.>>
After aggregation of contact is:
This diagram aggregate contacts.
1) Contact – aggregate contact.
2) RawContact1, RawContact2 – contacts involved in the aggregation.
3) Data(1..5) – contact data.
<<Constants for the contact aggregation exceptions table, which contains aggregation rules overriding those used by automatic aggregation. This type only supports query and update. Neither insert nor delete are supported.>>
Aggregated contact in the table will have the following structure:
The type of exception:
A reference to the _ID 
of the raw contact that the
rule applies to.
A reference to the
other _ID of the raw contact
 that the rule applies to.


Based on this structure:
 – It is convenient to read data from a table of aggregated contact.
 – It will simplify the operation a list of contacts.
 – Saving time and resources.
II. Possible solutions to this problem are:
To merge contacts is best aggregation.
Aggregation allows you to combine the contacts in a single database table, linking their keys.
 Aggregation contacts.
<<As soon as a raw contact is inserted or whenever its constituent data changes, the provider will check if the raw contact matches other existing raw contacts and if so will aggregate it with those. The aggregation is reflected in theContactsContract.RawContacts table by the change of the CONTACT_ID field, which is the reference to the aggregate contact.>>
This method involves the union contacts
<<There are two sets of APIs you can use to control aggregation explicitly: aggregation modes allow you to control automatic aggregation behaviors and aggregation exceptions allow you to override automated aggregation entirely.
Aggregation modes
You can set an aggregation mode for each raw contact individually. To do so, add a mode constant as the value of the AGGREGATION_MODE column in the RawContact row. The mode constants available include:
  • AGGREGATION_MODE_DEFAULT — normal mode, automatic aggregation is allowed.
  • AGGREGATION_MODE_DISABLED — automatic aggregation is not allowed. The raw contact will not be aggregated.
  • AGGREGATION_MODE_SUSPENDED — automatic aggregation is deactivated. If the raw contact is already a part of an aggregated contact when aggregation mode changes to suspended, it will remain in the aggregate, even if it changes in such a way that it no longer matches the other raw contacts in the aggregate.
Aggregation exceptions
To keep two raw contacts unconditionally together or unconditionally apart, you can add a row to the ContactsContract.AggregationExceptions table. Exceptions defined in the table override all automatic aggregation rules.>>