如何在Android上更新本机联系人照片? [英] How to update a native contact photo on android?

查看:68
本文介绍了如何在Android上更新本机联系人照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个示例应用程序,只是为了插入,更新和删除本机android联系人.我能够成功插入,更新和删除联系人.但是更新联系人照片时出现问题.下图是同一联系人有两个不同问题的观察结果.

I am working on one sample application just to insert, update and delete the native android contact. I am able to successfully insert, update and delete the contact. But the problem in updating the contact photo. Below images are the observation where the same contact having two different issue.

更新联系人后,第一张图像仍显示旧图像.但是,当我查看全部详细信息时,我能够查看新更新的联系人图像,如第二幅图像所示.下面是更新联系人图像的代码.

After updating the contact, first image is still displaying the old image. But where as when i view the full details i am able to view the newly updated contact image as shown in the second image. Below is the code for updating the contact image.

 mBitmap =getAllowedPhotoBitmap(photo);
 mBitmap = ThumbnailUtils.extractThumbnail(mBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
    if(mBitmap!=null){    // If an image is selected successfully
        mBitmap.compress(Bitmap.CompressFormat.PNG ,100, stream);
      op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
      op.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " +               ContactsContract.Data.MIMETYPE + "=?", new String[{String.valueOf(native_contactid), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE});
     op.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, stream.toByteArray());
     ops.add(op.build());
}

问题出在哪里,我要怎么做?

What is the problem and where i am going wrong?

推荐答案

这是一个开源应用程序,它可以执行以下操作:

Here is a open source app that does that: https://github.com/heinrisch/Contact-Picture-Sync/blob/master/src/heinrisch/contact/picture/sync/ContactHandler.java

这篇关于如何在Android上更新本机联系人照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆