I want to get photo from contacts, if some contacts don't have photo to return default photo(just silhouette), how can I do that? Thanks in advance, Wolf.
Asked
Active
Viewed 363 times
1 Answers
0
You can use ContactsContract.Contacts.Photo to get the picture for the specified contact.
Full example from the above documentation link:
public InputStream openDisplayPhoto(long contactId) {
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
try {
AssetFileDescriptor fd =
getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
return fd.createInputStream();
} catch (IOException e) {
return null;
}
}

Adrian Fâciu
- 12,414
- 3
- 53
- 68