2011-09-06 90 views
0

我想替換聯繫人的照片。但現在我所做的並不是用新的替換照片。 舊照片保持原樣。如何用新照片替換手機通訊錄中的聯繫人照片?

我將照片添加代碼

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()); 

    } 

它已經這麼久沒有身體甚至評論它,請建議我什麼。 感謝

回答