I have few numbers stored in my apps database. I wanted to match those numbers in contacts app and update that contact with mimetype. Basically how Whatsapp does. They sync all contacts and their app icon comes in contact.
I have done sync part and if i add new contact then i am able to show my app icon in the contact . But my requirement is to just update the existing contact.
This is what i have tried to update the contact,
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(addCallerIsSyncAdapterParameter(Data.CONTENT_URI, true))
.withValueBackReference(Data.RAW_CONTACT_ID,id)
.withValue(Data.MIMETYPE, MIMETYPE)
.withValue(Data.DATA1, "Username")
.withValue(Data.DATA2, "Ite's Me")
.build());
try {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e) {
e.printStackTrace();
}
and rawContactid
i am fetching from
Cursor cursor = context.getContentResolver().query(Data.CONTENT_URI, new String[] {Data.RAW_CONTACT_ID, Data.DISPLAY_NAME, Data.MIMETYPE, Data.CONTACT_ID },
ContactsContract.CommonDataKinds.Phone.NUMBER + "= ?",
new String[] {phonenumb}, null);
I am not able to add connections into that contact. What am i doing wrong. Can somebody please help me with this.
Thanks in advance.
insert your person data to new raw_contact, then merge it to existing raw_contact._id in your cotacts list using agregationexception.