I am looking for a way to programatically update a contact's photo with a given Bitmap image. I'm doing the following, but nothing happens. Neither is the picture being set nor occurs an error.
Cursor cursor = provider.query(ContactsContract.RawContacts.CONTENT_URI,
new String[]{ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.ACCOUNT_TYPE},
ContactsContract.RawContacts.ACCOUNT_TYPE +"=?",
new String[]{accountType},
null);
// Only one entry
if(cursor.moveToFirst())
{
id = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, stream);
byte[] bytes = stream.toByteArray();
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, Integer.parseInt(id))
.withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE)
.withValue(Photo.PHOTO, bytes)
.build());
}
provider.applyBatch(ops);
The image get loaded from a REST api, what seems to work properly since the bytes object actually is of the size of the downloaded image.