我想更换联系人的照片。但现在我所做的不是用新的照片替换照片。老照片仍然是原来的样子。
我添加照片的代码是
String thumbnail = "";
if(contact_map.get("photos")!=null)
{
thumbnail = contact_map.get("photos").toString();
Log.i("--: VALUE :--","thumbnail = "+thumbnail);
URL image_url = null;
Bitmap bitmap_image = null;
ByteArrayOutputStream stream_image = null;
try
{
image_url = new URL(thumbnail);
bitmap_image = BitmapFactory.decodeStream(image_url.openConnection().getInputStream());
stream_image = new ByteArrayOutputStream();
bitmap_image.compress(Bitmap.CompressFormat.JPEG , 100, stream_image);
}
catch(Exception e)
{
Log.e("My Exception",""+e.getMessage());
}
//INSERT IMAGE
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, stream_image.toByteArray())
.build());
}好久没人评论了,请给我提点建议吧。谢谢
发布于 2011-11-08 22:59:11
以下是示例http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.DisplayPhoto.html的代码
https://stackoverflow.com/questions/7316152
复制相似问题