I am trying to create a rawcontact in android that has a specific contact id, so it is linked to other rawcontacts with the same contactid (not rawcontactid).
The problem is I am unable to insert the Contact_ID into the ContentProviderOpertations. Using the following code return "Insert failed"
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int id = (int) contactId;
String condition = Data.RAW_CONTACT_ID + "=?";
String[] parameters = { "" + id };
try {
String accountName = account.name;
String accountType = account.type;
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, accountType)
.withValue(RawContacts.ACCOUNT_NAME, accountName).build());
ops.add(getAccountGroupOperation(account));
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.CONTACT_ID, "" + id)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, contact.getName())
.build());
MyApplication.getAppContext().getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
...
}
What am I doing wrong?