public static final class ContactsContract.StreamItems extends Object implements BaseColumns, ContactsContract.StreamItemsColumns
Constants for the stream_items table, which contains social stream updates from the user's contact list.
Only a certain number of stream items will ever be stored under a given raw contact.
Users of this API can query CONTENT_LIMIT_URI
to
determine this limit, and should restrict the number of items inserted in any given
transaction correspondingly. Insertion of more items beyond the limit will
automatically lead to deletion of the oldest items, by ContactsContract.StreamItemsColumns.TIMESTAMP
.
Access to the social stream through these URIs requires additional permissions beyond the read/write contact permissions required by the provider. Querying for social stream data requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating social stream items requires android.permission.WRITE_SOCIAL_STREAM permission.
The content URIs to the insert, update and delete operations are required to have the account
information matching that of the owning raw contact as query parameters, namely
ContactsContract.SyncColumns.ACCOUNT_TYPE
and ContactsContract.SyncColumns.ACCOUNT_NAME
.
ContactsContract.RawContactsColumns.DATA_SET
isn't required.
Social stream updates are always associated with a raw contact. There are a couple of ways to insert these entries.
ContactsContract.RawContacts.StreamItems.CONTENT_DIRECTORY
sub-path of a raw contact:ContentValues values = new ContentValues(); values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); values.put(StreamItems.TIMESTAMP, timestamp); values.put(StreamItems.COMMENTS, "3 people reshared this"); Uri.Builder builder = RawContacts.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, rawContactId); builder.appendEncodedPath(RawContacts.StreamItems.CONTENT_DIRECTORY); builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName); builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType); Uri streamItemUri = getContentResolver().insert(builder.build(), values); long streamItemId = ContentUris.parseId(streamItemUri);
ContactsContract.Contacts.CONTENT_URI
:ContentValues values = new ContentValues(); values.put(StreamItems.RAW_CONTACT_ID, rawContactId); values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); values.put(StreamItems.TIMESTAMP, timestamp); values.put(StreamItems.COMMENTS, "3 people reshared this"); Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon(); builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName); builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType); Uri streamItemUri = getContentResolver().insert(builder.build(), values); long streamItemId = ContentUris.parseId(streamItemUri);
Once a ContactsContract.Contacts.StreamItems
entry has been inserted, photos associated with that
social update can be inserted. For example, after one of the insertions above,
photos could be added to the stream item in one of the following ways:
values.clear(); values.put(StreamItemPhotos.SORT_INDEX, 1); values.put(StreamItemPhotos.PHOTO, photoData); getContentResolver().insert(Uri.withAppendedPath( ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId), StreamItems.StreamItemPhotos.CONTENT_DIRECTORY), values);
CONTENT_PHOTO_URI
:values.clear(); values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); values.put(StreamItemPhotos.SORT_INDEX, 1); values.put(StreamItemPhotos.PHOTO, photoData); getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values);
Note that this latter form allows the insertion of a stream item and its
photos in a single transaction, by using ContentProviderOperation
with
back references to populate the stream item ID in the ContentValues
.
ContactsContract.Contacts.CONTENT_URI
URI. Only social stream entries that were
created by the calling package can be updated.ContactsContract.Contacts.CONTENT_URI
URI. Only social stream entries that were
created by the calling package can be deleted.Cursor c = getContentResolver().query(Uri.withAppendedPath( ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId), Contacts.StreamItems.CONTENT_DIRECTORY), null, null, null, null);
Cursor c = getContentResolver().query(Contacts.CONTENT_URI.buildUpon() .appendPath(lookupKey) .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(), null, null, null, null);
Cursor c = getContentResolver().query(Uri.withAppendedPath( ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), RawContacts.StreamItems.CONTENT_DIRECTORY)), null, null, null, null);
Cursor c = getContentResolver().query(ContentUris.withAppendedId( StreamItems.CONTENT_URI, streamItemId), null, null, null, null);
Modifier and Type | Class and Description |
---|---|
static class |
ContactsContract.StreamItems.StreamItemPhotos
A sub-directory of a single stream item entry that contains all of its
photo rows.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONTENT_ITEM_TYPE
The MIME type of a single stream item.
|
static Uri |
CONTENT_LIMIT_URI
This URI allows the caller to query for the maximum number of stream items
that will be stored under any single raw contact.
|
static Uri |
CONTENT_PHOTO_URI
A content:// style URI for the photos stored in a sub-table underneath
stream items.
|
static String |
CONTENT_TYPE
The MIME type of a directory of stream items.
|
static Uri |
CONTENT_URI
The content:// style URI for this table, which handles social network stream
updates for the user's contacts.
|
static String |
MAX_ITEMS
Queries to
CONTENT_LIMIT_URI will
contain this column, with the value indicating the maximum number of
stream items that will be stored under any single raw contact. |
_COUNT, _ID
ACCOUNT_NAME, ACCOUNT_TYPE, COMMENTS, CONTACT_ID, CONTACT_LOOKUP_KEY, DATA_SET, RAW_CONTACT_ID, RAW_CONTACT_SOURCE_ID, RES_ICON, RES_LABEL, RES_PACKAGE, SYNC1, SYNC2, SYNC3, SYNC4, TEXT, TIMESTAMP
public static final Uri CONTENT_URI
public static final Uri CONTENT_PHOTO_URI
A content:// style URI for the photos stored in a sub-table underneath
stream items. This is only used for inserts, and updates - queries and deletes
for photos should be performed by appending
ContactsContract.StreamItems.StreamItemPhotos.CONTENT_DIRECTORY
path to URIs for a
specific stream item.
When using this URI, the stream item ID for the photo(s) must be identified
in the ContentValues
passed in.
public static final Uri CONTENT_LIMIT_URI
public static final String CONTENT_TYPE
public static final String CONTENT_ITEM_TYPE
public static final String MAX_ITEMS
CONTENT_LIMIT_URI
will
contain this column, with the value indicating the maximum number of
stream items that will be stored under any single raw contact.