2

I have an account and a sync adapter which add new raw contacts with corresponding private data entries. the contacts I'm creating are phone number based, meaning I'm creating a new entry per existing phone number.

How do I merge my raw contact with the existing raw contact that was linked to the existing phone number?

I've tried creating a new phone number entry in the data table, and link it to the raw contacts I'm adding. it works, but It's creating a duplication phone number.

I've also tried setting the contact ID, display name, secondery display name but with no success... the only data I can change in raw contacts is the account name and type, and the columns SYNC1...SYNC4

Ofer
  • 127
  • 1
  • 10
  • This is what solved my case: http://stackoverflow.com/questions/8741788/insert-rawcontact-with-a-specific-contactid/8868740#8868740 – Ofer Sep 11 '12 at 11:48

2 Answers2

0

Raw contacts table holds 1 row per contact, Data table may hold any number of rows for each row in Raw table.

To add new phone numbers to a contact, Insert rows in Data table with ContactsContract.Data.RAW_CONTACT_ID set to the Raw table row _id of that contact.

S.D.
  • 29,290
  • 3
  • 79
  • 130
  • Thanks for answering, but the question isn't how to add a phone number to an exiting raw contact, but how to aggregate my raw contact with an existing raw contact that has a phone number. – Ofer Sep 10 '12 at 06:40
  • I may have misunderstood your question. Anyways it'll help to have a look at table structures of [RawContacts](http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html) and [Data](http://developer.android.com/reference/android/provider/ContactsContract.Data.html). – S.D. Sep 10 '12 at 10:51
0

You need to update an entry in the AggregationExceptions table. See: http://developer.android.com/reference/android/provider/ContactsContract.AggregationExceptions.html

An example code that supports batch joining if needed:

ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
Builder builder = ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI);
builder.withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER);
builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, raw1);
builder.withValue(AggregationExceptions.RAW_CONTACT_ID2, raw2);
operations.add(builder.build());
contentResolver.applyBatch(ContactsContract.AUTHORITY, tempArrayList);
marmor
  • 27,641
  • 11
  • 107
  • 150
  • what is (and how we obtain that) `raw1` and `raw2` values? – Favolas Aug 11 '20 at 11:22
  • it's the raw-contact-id's of the two raw-contacts you need to join / separate. the query to get raw-contact-id's will differ depending on your app, but if you already have contact-id's of the two contacts, I can show you how to obtain the raw-contact-id's of each. – marmor Aug 11 '20 at 11:25