I am trying to show contact pictures in my application but I am getting pictures of those who were added manually only and not those which are synced with facebook. How to w
I get the picture for all the contacts even some that are synced from facebook with this code:
* @param context
* The context used to retrieve the image.
* @return The image of the user that is saved in the address book or null if
* the user does not exists or has no image.
*/
public Bitmap getContactPhoto(Context context) {
ContentResolver contentResolver = context.getContentResolver();
Uri photoUri = getCurrentUri(contentResolver);
if (photoUri != null) {
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(
contentResolver, photoUri);
if (input != null) {
return BitmapFactory.decodeStream(input);
}
} else {
Log.d(getClass().getSimpleName(), "No photo Uri");
}
return null;
}
private Uri getCurrentUri(ContentResolver contentResolver) {
Cursor contact = contentResolver.query(lookUpUri,
new String[] { ContactsContract.Contacts._ID }, null, null, null);
if (contact.moveToFirst()) {
long userId = contact.getLong(contact.getColumnIndex(ContactsContract.Contacts._ID));
return ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, userId);
}
return null;
}
Maybe have a look at the code again that creates your photoId. Don't use the Id of an photo in the data table to create the Uri. I also tried that and retrieving the photo worked for me only if I use an uri that links directly to the merged user. You will then get the default image for this person regardless from where it was synced.