How to update your own contact photo on android?

I am working on one example application to insert, update and delete a native contact with Android. I can successfully insert, update and delete a contact. But the problem is updating the contact photo. The image below is an observation where the same contact has two different problems. figure 1figure2

After updating the contact, the first image still displays the old image. But where, when I look at the full information, I can view the updated contact image, as shown in the second image. Below is the contact image update code.

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 am I mistaken?

+4
source share
2 answers

this file will help you set the image for the contact with the contact id

https://github.com/heinrisch/Contact-Picture-Sync/blob/master/src/heinrisch/contact/picture/sync/ContactHandler.java

 void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { // Check for the request code, we might be usign multiple if (requestCode == PICK_CONTACT_REQUEST) { Uri contactUri = data.getData(); String[] projection = {Phone.CONTACT_ID,Phone.NUMBER,ContactsContract.Data.RAW_CONTACT_ID,ContactsContract.Data._ID }; Cursor cursor = getContentResolver().query(contactUri, projection, null, null, null); cursor.moveToFirst(); int columcontactID = cursor.getColumnIndex(Phone.CONTACT_ID); String contactID = cursor.getString(columcontactID); Bitmap item = (imgBg.getVisibleRectangleBitmap()); setContactPicture(AtWallpaperDetails.this, contactID, item); } } } 
0
source

All Articles