ContactsContract.Contacts.Photo


public static final class ContactsContract.Contacts.Photo
extends Object implements BaseColumns, ContactsContract.DataColumnsWithJoins

java.lang.Object
   ↳ android.provider.ContactsContract.Contacts.Photo


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 ContactsContract.Contacts#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 ContactsContract.Contacts.CONTENT_URI or ContactsContract.Contacts.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.

Inherited constants

Inherited methods

Constants

CONTENT_DIRECTORY

Added in API level 5
public static final String CONTENT_DIRECTORY

The directory twig for this sub-table

Constant Value: "photo"

DISPLAY_PHOTO

Added in API level 14
public static final String DISPLAY_PHOTO

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

Constant Value: "display_photo"

PHOTO

Added in API level 11
public static final String PHOTO

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"

PHOTO_FILE_ID

Added in API level 14
public static final String PHOTO_FILE_ID

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

Type: NUMBER

Constant Value: "data14"