已经问了一个但没有答案。如何更新已经没有图片的联系人的图片。代码是。
if(check_image == null) {
Bitmap bmImage = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);
byte[] b = baos.toByteArray();
Toast.makeText(getApplicationContext(), "if", Toast.LENGTH_LONG).show();
ops.add(ContentProviderOperation
.newInsert(
ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID,
0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.Photo.DATA15,
b).build());
}
else {
Toast.makeText(getApplicationContext(), "else", Toast.LENGTH_LONG).show();
ops.add(ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(
ContactsContract.Data.CONTACT_ID
+ " = ? AND "
+ ContactsContract.Data.MIMETYPE
+ " = ?",
new String[] {
contactid,
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE })
.withValue(Photo.DATA15, image_byte).build());
}