开发者

How to replace photos of contacts in Phone Contacts with new Photos?

I want to replace photos of contacts. But now what I am doing is not replacing photos with new one. The old photo remains as it is.

My code for adding photos is

String thumbnail = "";
    if(contact_map.get("photos")!=null)
    {
        thumbnail = con开发者_如何学Gotact_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());

    }

Its been so long no body even commented it please suggest me anything. Thanks


Here's the code sample http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.DisplayPhoto.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜