问题
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
回答1:
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.
回答2:
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);
来源:https://stackoverflow.com/questions/12340756/merging-raw-contacts