I saw this question and answer, but adding the phone information (and even email) still does not cause the contact information to aggregate properly (when I check the People app, I can see multiple entries under the same name).
Here is the code I use to test it.
//get the account
Account acct = null;
Account[] accounts = AccountManager.get(getContext()).getAccounts();
for (Account acc : accounts){
acct = acc;
}//assuming there's only one account in there (in my case I know there is)
//loop a few times, creating a new contact each time. In theory, if they have the same name they should aggregate
for(int i=0; i<3; i++){
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, acct.type)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, acct.name)
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "ContactName")
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, "1234567890")
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, 1)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, "email@address.com")
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, 1)
.build());
try{
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e) {
Log.e("Contacts", "Something went wrong during creation! " + e);
e.printStackTrace();
}
}