0

To get contact photo uri you can simply fallow the docs:

Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
return Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

But in my case I want to show all the RAW_CONTACTS that are part of a single contact, there for I need their high res photo uri. So how can I obtain one?

Note that I am not interested in the thumbnail BLOB that you can find in the Data table under the Contacts.Photo.PHOTO column, but the high res image.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216

1 Answers1

2

You're looking for ContactsContract.RawContacts.DisplayPhoto,

Here's the official usage example from the docs (it's for writing a photo into a RawContact):

public void writeDisplayPhoto(long rawContactId, byte[] photo) {
     Uri rawContactPhotoUri = Uri.withAppendedPath(
             ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
             RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
     try {
         AssetFileDescriptor fd =
             getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw");
         OutputStream os = fd.createOutputStream();
         os.write(photo);
         os.close();
         fd.close();
     } catch (IOException e) {
         // Handle error cases.
     }
 }

Here's how to read it:

public byte[] readDisplayPhoto(long rawContactId) {
     byte[] photo;
     Uri rawContactPhotoUri = Uri.withAppendedPath(
             ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
             RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
     try {
         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "r");
         FileInputStream is = fd.createInputStream();
         is.read(photo);
         is.close();
         fd.close();
         return photo
     } catch (IOException e) {
         // Handle error cases.
     }
 }
marmor
  • 27,641
  • 11
  • 107
  • 150