Added in API level 5

Photo


class Photo : BaseColumns, ContactsContract.DataColumnsWithJoins
kotlin.Any
   ↳ 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 CONTENT_URI or CONTENT_LOOKUP_URI.

Summary

Constants
static String

The directory twig for this sub-table

static String

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

static String

Thumbnail photo of the raw contact.

static String

Full-size photo file ID of the raw contact.

Inherited constants

Constants

CONTENT_DIRECTORY

Added in API level 5
static val CONTENT_DIRECTORY: String

The directory twig for this sub-table

Value: "photo"

DISPLAY_PHOTO

Added in API level 14
static val DISPLAY_PHOTO: String

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

Value: "display_photo"

PHOTO

Added in API level 11
static val PHOTO: String

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

Type: BLOB

Value: "data15"

PHOTO_FILE_ID

Added in API level 14
static val PHOTO_FILE_ID: String

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

Type: NUMBER

Value: "data14"