Android : load actual photo of contact in android 2.3.*

on Monday, October 27, 2014


Still facing with problem of loading actual contact's photos in android 2.3.*... Tried many different ways but can't to get latest photo from phonebook. My last code:



Uri uri = getPhotoUri(context, contact.getPhoneBookContactId());
Picasso.with(context).load(uri).error( R.drawable.contact_icon ).into(imageViewLowGB);


where getPhotoUri:



public static Uri getPhotoUri(Context context,final int contactId) {
try {
Cursor cur = context.getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID + "=" + contactId + " AND "
+ ContactsContract.Data.MIMETYPE + "='"
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'", null,
null);
if (cur != null) {
if (!cur.moveToFirst()) {
return null; // no photo
}
} else {
return null; // error in cursor process
}
} catch (Exception e) {
Log.e( ImageManager.class.getSimpleName(), "error getPhotoUri" +e.getMessage() );
return null;
}
Uri person = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI,contactId );
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}


This code give me photo, but if change photo, old photo loading again and again (( Please, someone help me...This problem only on 2.3.* versions(


0 comments:

Post a Comment