public static final class

ContactsContract.StreamItemPhotos

extends Object
implements BaseColumns ContactsContract.StreamItemPhotosColumns
java.lang.Object
   ↳ android.provider.ContactsContract.StreamItemPhotos

Class Overview

Constants for the stream_item_photos table, which contains photos associated with social stream updates.

Access to social stream photos requires additional permissions beyond the read/write contact permissions required by the provider. Querying for social stream photos requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission.

Operations

Insert

Social stream photo entries are associated with a social stream item. Photos can be inserted into a social stream item in a couple of ways:

Via the CONTENT_DIRECTORY sub-path of a stream item:
 ContentValues values = new ContentValues();
 values.put(StreamItemPhotos.SORT_INDEX, 1);
 values.put(StreamItemPhotos.PHOTO, photoData);
 Uri photoUri = getContentResolver().insert(Uri.withAppendedPath(
     ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
     StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), values);
 long photoId = ContentUris.parseId(photoUri);
 
Via the CONTENT_PHOTO_URI URI:
 ContentValues values = new ContentValues();
 values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
 values.put(StreamItemPhotos.SORT_INDEX, 1);
 values.put(StreamItemPhotos.PHOTO, photoData);
 Uri photoUri = getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values);
 long photoId = ContentUris.parseId(photoUri);
 

Update

Updates can only be made against a specific ContactsContract.StreamItems.StreamItemPhotos entry, identified by both the stream item ID it belongs to and the stream item photo ID. This can be specified in two ways.

Via the CONTENT_DIRECTORY sub-path of a stream item:
 ContentValues values = new ContentValues();
 values.put(StreamItemPhotos.PHOTO, newPhotoData);
 getContentResolver().update(
     ContentUris.withAppendedId(
         Uri.withAppendedPath(
             ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
             StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
         streamItemPhotoId), values, null, null);
 
Via the CONTENT_PHOTO_URI URI:
 ContentValues values = new ContentValues();
 values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
 values.put(StreamItemPhotos.PHOTO, newPhotoData);
 getContentResolver().update(StreamItems.CONTENT_PHOTO_URI, values);
 

Delete
Deletes can be made against either a specific photo item in a stream item, or against all or a selected subset of photo items under a stream item. For example:
Deleting a single photo via the CONTENT_DIRECTORY sub-path of a stream item:
 getContentResolver().delete(
     ContentUris.withAppendedId(
         Uri.withAppendedPath(
             ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
             StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
         streamItemPhotoId), null, null);
 
Deleting all photos under a stream item
 getContentResolver().delete(
     Uri.withAppendedPath(
         ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
         StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), null, null);
 
Query
Querying for a specific photo in a stream item
 Cursor c = getContentResolver().query(
     ContentUris.withAppendedId(
         Uri.withAppendedPath(
             ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
             StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
         streamItemPhotoId), null, null, null, null);
 
Querying for all photos in a stream item
 Cursor c = getContentResolver().query(
     Uri.withAppendedPath(
         ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
         StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
     null, null, null, StreamItemPhotos.SORT_INDEX);
 
The record will contain both a PHOTO_FILE_ID and a PHOTO_URI. The PHOTO_FILE_ID can be used in conjunction with the ContactsContract.DisplayPhoto API to retrieve photo content, or you can open the PHOTO_URI as an asset file, as follows:
 public InputStream openDisplayPhoto(String photoUri) {
     try {
         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(photoUri, "r");
         return fd.createInputStream();
     } catch (IOException e) {
         return null;
     }
 }
 
 
 

Summary

Constants
String PHOTO

The binary representation of the photo.

[Expand]
Inherited Constants
From interface android.provider.BaseColumns
From interface android.provider.ContactsContract.StreamItemPhotosColumns
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String PHOTO

Since: API Level 15

The binary representation of the photo. Any size photo can be inserted; the provider will resize it appropriately for storage and display.

This is only intended for use when inserting or updating a stream item photo. To retrieve the photo that was stored, open PHOTO_URI as an asset file.

Type: BLOB

Constant Value: "photo"