The code at the bottom shows how I update contact pictures from my app. This works well, if the user uses sim, phone and google contacts and similar. But if he uses the outlook app, the outlook app does overwrite the images set by my app again after some time.
Can I somehow solve that? Can I force to overwrite the outlook image as well so that outlook syncs my new photo instead of their old one?
Code
byte[] photo = ImageUtil.convertImageToByteArray(bitmap, true);
ContentValues values = new ContentValues();
int photoId = -1;
String where = ContactsContract.Data.RAW_CONTACT_ID + " == " +
contact.getRawId() + " AND " + ContactsContract.Contacts.Data.MIMETYPE + "=='" +
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
Cursor cursor = MainApp.get().getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
null,
where,
null,
null);
int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID);
if (cursor.moveToFirst()) {
photoId = cursor.getInt(idIdx);
}
cursor.close();
values.put(ContactsContract.Data.RAW_CONTACT_ID, contact.getRawId());
values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, photo);
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
if (photoId >= 0) {
MainApp.get().getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
ContactsContract.Data._ID + " = " + photoId, null);
} else {
MainApp.get().getContentResolver().insert(
ContactsContract.Data.CONTENT_URI,
values);
}