I’m having a BIG touble when adding duplicate contact fields in Android 2.1 update 1
please have a look at my code:
ArrayList<ContentProviderOperation> op_list = new ArrayList<ContentProviderOperation>();
op_list.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
// first and last names
op_list.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.GIVEN_NAME, "MyFirstName")
.withValue(StructuredName.FAMILY_NAME, "MyLastName")
.build());
try{
ContentProviderResult[] results = cResolver.applyBatch(ContactsContract.AUTHORITY, op_list);
}catch(Exception e){
e.printStackTrace();
}
Try to run this piece of code in a 20 iteration loop, then go to the contacts application
you will see only 8 contacts hanging there!!
This problem happens when also when I insert duplicate emails, phones, organizations.
Try it in a loop from 0->200, android will go crazy!
is there a problem in my code? is there any solution to this?
any help will be really appreciated …
Thanks!
After 2 non sleep days… rereading my code and rewriting my classes
I found the solution to this: there is a column that I was not aware of, and it didn’t even exist in earlier APIs called: AGGREGATION_MODE
so the solution turned out to be this: