Most visited

Recently visited

Added in API level 5

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 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.

Inherited constants

From interface android.provider.BaseColumns
From interface android.provider.ContactsContract.DataColumns
From interface android.provider.ContactsContract.StatusColumns
From interface android.provider.ContactsContract.RawContactsColumns
From interface android.provider.ContactsContract.ContactsColumns
From interface android.provider.ContactsContract.ContactNameColumns
From interface android.provider.ContactsContract.ContactOptionsColumns
From interface android.provider.ContactsContract.ContactStatusColumns
From interface android.provider.ContactsContract.DataUsageStatColumns

Inherited methods

From class java.lang.Object

Constants

CONTENT_DIRECTORY

Added in API level 5
String CONTENT_DIRECTORY

The directory twig for this sub-table

Constant Value: "photo"

DISPLAY_PHOTO

Added in API level 14
String DISPLAY_PHOTO

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

Constant Value: "display_photo"

PHOTO

Added in API level 11
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
String PHOTO_FILE_ID

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

Type: NUMBER

Constant Value: "data14"

Hooray!