a function to get a contacts photo uri:
public Uri getPhotoUri(Integer contactid) {
Cursor photoCur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'", null, ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
photoCur.moveToPosition(contactid);
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, photoCur.getLong(photoCur.getColumnIndex(ContactsContract.Contacts._ID)));
Uri photo = Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
return photo;
}
and calling that function (contactimage is an ImageView):
Uri contactphoto = getPhotoUri(2);
contactimage.setImageURI(contactphoto);
try {
String nullString = contactimage.getDrawable().toString();
} catch (java.lang.NullPointerException ex) {
contactimage.setImageResource(R.drawable.contactplaceholder);
}