Android APIs
public static final class

ContactsContract.Contacts.Photo

extends Object
implements BaseColumns ContactsContract.DataColumnsWithJoins
java.lang.Object
   ↳ android.provider.ContactsContract.Contacts.Photo

Class Overview

A read-only sub-directory of a single contact that contains the contact's primary photo. The photo may be stored in up to two ways - the default "photo" is a thumbnail-sized image stored directly in the data row, while the "display photo", if present, is a larger version stored as a file.

Usage example:

Retrieving the thumbnail-sized photo
 public InputStream openPhoto(long contactId) {
     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
     Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
     Cursor cursor = getContentResolver().query(photoUri,
          new String[] {Contacts.Photo.PHOTO}, null, null, null);
     if (cursor == null) {
         return null;
     }
     try {
         if (cursor.moveToFirst()) {
             byte[] data = cursor.getBlob(0);
             if (data != null) {
                 return new ByteArrayInputStream(data);
             }
         }
     } finally {
         cursor.close();
     }
     return null;
 }
 
Retrieving the larger photo version
 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;
     }
 }
 

You may also consider using the convenience method openContactPhotoInputStream(ContentResolver, Uri, boolean) to retrieve the raw photo contents of either the thumbnail-sized or the full-sized photo.

This directory can be used either with a CONTENT_URI or CONTENT_LOOKUP_URI.

Summary

Constants
String CONTENT_DIRECTORY The directory twig for this sub-table
String DISPLAY_PHOTO The directory twig for retrieving the full-size display photo.
String PHOTO Thumbnail photo of the raw contact.
String PHOTO_FILE_ID Full-size photo file ID of the raw contact.
[Expand]
Inherited Constants
From interface android.provider.BaseColumns
From interface android.provider.ContactsContract.ContactNameColumns
From interface android.provider.ContactsContract.ContactOptionsColumns
From interface android.provider.ContactsContract.ContactStatusColumns
From interface android.provider.ContactsContract.ContactsColumns
From interface android.provider.ContactsContract.DataColumns
From interface android.provider.ContactsContract.DataUsageStatColumns
From interface android.provider.ContactsContract.RawContactsColumns
From interface android.provider.ContactsContract.StatusColumns
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String CONTENT_DIRECTORY

Added in API level 5

The directory twig for this sub-table

Constant Value: "photo"

public static final String DISPLAY_PHOTO

Added in API level 14

The directory twig for retrieving the full-size display photo.

Constant Value: "display_photo"

public static final String PHOTO

Added in API level 11

Thumbnail photo of the raw contact. This is the raw bytes of an image that could be inflated using BitmapFactory.

Type: BLOB

Constant Value: "data15"

public static final String PHOTO_FILE_ID

Added in API level 14

Full-size photo file ID of the raw contact. See ContactsContract.DisplayPhoto.

Type: NUMBER

Constant Value: "data14"