/* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.provider; import android.accounts.Account; import android.content.ContentProviderClient; import android.content.ContentProviderOperation; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.CursorEntityIterator; import android.content.Entity; import android.content.EntityIterator; import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteException; import android.graphics.Rect; import android.net.Uri; import android.os.RemoteException; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Pair; import android.view.View; import java.io.ByteArrayInputStream; import java.io.InputStream; /** *
* The contract between the contacts provider and applications. Contains * definitions for the supported URIs and columns. These APIs supersede * {@link Contacts}. *
** ContactsContract defines an extensible database of contact-related * information. Contact information is stored in a three-tier data model: *
** Other tables include: *
*Type: TEXT
*/ public static final String ACCOUNT_NAME = "account_name"; /** * The type of account to which this row belongs, which when paired with * {@link #ACCOUNT_NAME} identifies a specific account. *Type: TEXT
*/ public static final String ACCOUNT_TYPE = "account_type"; /** * String that uniquely identifies this row to its source account. *Type: TEXT
*/ public static final String SOURCE_ID = "sourceid"; /** * Version number that is updated whenever this row or its related data * changes. *Type: INTEGER
*/ public static final String VERSION = "version"; /** * Flag indicating that {@link #VERSION} has changed, and this row needs * to be synchronized by its owning account. *Type: INTEGER (boolean)
*/ public static final String DIRTY = "dirty"; } /** * Columns of {@link ContactsContract.Contacts} that track the user's * preferences for, or interactions with, the contact. * * @see Contacts * @see RawContacts * @see ContactsContract.Data * @see PhoneLookup * @see ContactsContract.Contacts.AggregationSuggestions */ protected interface ContactOptionsColumns { /** * The number of times a contact has been contacted *Type: INTEGER
*/ public static final String TIMES_CONTACTED = "times_contacted"; /** * The last time a contact was contacted. *Type: INTEGER
*/ public static final String LAST_TIME_CONTACTED = "last_time_contacted"; /** * Is the contact starred? *Type: INTEGER (boolean)
*/ public static final String STARRED = "starred"; /** * URI for a custom ringtone associated with the contact. If null or missing, * the default ringtone is used. *Type: TEXT (URI to the ringtone)
*/ public static final String CUSTOM_RINGTONE = "custom_ringtone"; /** * Whether the contact should always be sent to voicemail. If missing, * defaults to false. *Type: INTEGER (0 for false, 1 for true)
*/ public static final String SEND_TO_VOICEMAIL = "send_to_voicemail"; } /** * Columns of {@link ContactsContract.Contacts} that refer to intrinsic * properties of the contact, as opposed to the user-specified options * found in {@link ContactOptionsColumns}. * * @see Contacts * @see ContactsContract.Data * @see PhoneLookup * @see ContactsContract.Contacts.AggregationSuggestions */ protected interface ContactsColumns { /** * The display name for the contact. *Type: TEXT
*/ public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY; /** * Reference to the row in the RawContacts table holding the contact name. *Type: INTEGER REFERENCES raw_contacts(_id)
* @hide */ public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id"; /** * Reference to the row in the data table holding the photo. *Type: INTEGER REFERENCES data(_id)
*/ public static final String PHOTO_ID = "photo_id"; /** * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of * any {@link CommonDataKinds.GroupMembership} for this contact. */ public static final String IN_VISIBLE_GROUP = "in_visible_group"; /** * An indicator of whether this contact has at least one phone number. "1" if there is * at least one phone number, "0" otherwise. *Type: INTEGER
*/ public static final String HAS_PHONE_NUMBER = "has_phone_number"; /** * An opaque value that contains hints on how to find the contact if * its row id changed as a result of a sync or aggregation. */ public static final String LOOKUP_KEY = "lookup"; } /** * @see Contacts */ protected interface ContactStatusColumns { /** * Contact presence status. See {@link StatusUpdates} for individual status * definitions. *Type: NUMBER
*/ public static final String CONTACT_PRESENCE = "contact_presence"; /** * Contact Chat Capabilities. See {@link StatusUpdates} for individual * definitions. *Type: NUMBER
* @hide */ public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability"; /** * Contact's latest status update. *Type: TEXT
*/ public static final String CONTACT_STATUS = "contact_status"; /** * The absolute time in milliseconds when the latest status was * inserted/updated. *Type: NUMBER
*/ public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts"; /** * The package containing resources for this status: label and icon. *Type: TEXT
*/ public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package"; /** * The resource ID of the label describing the source of contact * status, e.g. "Google Talk". This resource is scoped by the * {@link #CONTACT_STATUS_RES_PACKAGE}. *Type: NUMBER
*/ public static final String CONTACT_STATUS_LABEL = "contact_status_label"; /** * The resource ID of the icon for the source of contact status. This * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}. *Type: NUMBER
*/ public static final String CONTACT_STATUS_ICON = "contact_status_icon"; } /** * Constants for various styles of combining given name, family name etc into * a full name. For example, the western tradition follows the pattern * 'given name' 'middle name' 'family name' with the alternative pattern being * 'family name', 'given name' 'middle name'. The CJK tradition is * 'family name' 'middle name' 'given name', with Japanese favoring a space between * the names and Chinese omitting the space. * @hide */ public interface FullNameStyle { public static final int UNDEFINED = 0; public static final int WESTERN = 1; /** * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine * which specific language it belongs to: Chinese, Japanese or Korean. */ public static final int CJK = 2; public static final int CHINESE = 3; public static final int JAPANESE = 4; public static final int KOREAN = 5; } /** * Constants for various styles of capturing the pronunciation of a person's name. * @hide */ public interface PhoneticNameStyle { public static final int UNDEFINED = 0; /** * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly * shown in UIs, but used for searches and sorting. */ public static final int PINYIN = 3; /** * Hiragana and Katakana are two common styles of writing out the pronunciation * of a Japanese names. */ public static final int JAPANESE = 4; /** * Hangul is the Korean phonetic alphabet. */ public static final int KOREAN = 5; } /** * Types of data used to produce the display name for a contact. Listed in the order * of increasing priority. * * @hide */ public interface DisplayNameSources { public static final int UNDEFINED = 0; public static final int EMAIL = 10; public static final int PHONE = 20; public static final int ORGANIZATION = 30; public static final int NICKNAME = 35; public static final int STRUCTURED_NAME = 40; } /** * Contact name and contact name metadata columns in the RawContacts table. * * @see Contacts * @see RawContacts * @hide */ protected interface ContactNameColumns { /** * The kind of data that is used as the display name for the contact, such as * structured name or email address. See DisplayNameSources. * * TODO: convert DisplayNameSources to a link after it is un-hidden */ public static final String DISPLAY_NAME_SOURCE = "display_name_source"; /** ** The standard text shown as the contact's display name, based on the best * available information for the contact (for example, it might be the email address * if the name is not available). * The information actually used to compute the name is stored in * {@link #DISPLAY_NAME_SOURCE}. *
** A contacts provider is free to choose whatever representation makes most * sense for its target market. * For example in the default Android Open Source Project implementation, * if the display name is * based on the structured name and the structured name follows * the Western full-name style, then this field contains the "given name first" * version of the full name. *
* * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE */ public static final String DISPLAY_NAME_PRIMARY = "display_name"; /** *
* An alternative representation of the display name, such as "family name first" * instead of "given name first" for Western names. If an alternative is not * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}. *
** A contacts provider is free to provide alternatives as necessary for * its target market. * For example the default Android Open Source Project contacts provider * currently provides an * alternative in a single case: if the display name is * based on the structured name and the structured name follows * the Western full name style, then the field contains the "family name first" * version of the full name. * Other cases may be added later. *
*/ public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt"; /** * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}. See * PhoneticNameStyle. * * TODO: convert PhoneticNameStyle to a link after it is un-hidden */ public static final String PHONETIC_NAME_STYLE = "phonetic_name_style"; /** ** Pronunciation of the full name in the phonetic alphabet specified by * {@link #PHONETIC_NAME_STYLE}. *
** The value may be set manually by the user. * This capability is is of interest only in countries * with commonly used phonetic * alphabets, such as Japan and Korea. See PhoneticNameStyle. *
* * TODO: convert PhoneticNameStyle to a link after it is un-hidden */ public static final String PHONETIC_NAME = "phonetic_name"; /** * Sort key that takes into account locale-based traditions for sorting * names in address books. The default * sort key is {@link #DISPLAY_NAME_PRIMARY}. For Chinese names * the sort key is the name's Pinyin spelling, and for Japanese names * it is the Hiragana version of the phonetic name. */ public static final String SORT_KEY_PRIMARY = "sort_key"; /** * Sort key based on the alternative representation of the full name, * {@link #DISPLAY_NAME_ALTERNATIVE}. Thus for Western names, * it is the one using the "family name first" format. */ public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt"; } /** * URI parameter and cursor extras that return counts of rows grouped by the * address book index, which is usually the first letter of the sort key. * When this parameter is supplied, the row counts are returned in the * cursor extras bundle. * * @hide */ public final static class ContactCounts { /** * Add this query parameter to a URI to get back row counts grouped by * the address book index as cursor extras. For most languages it is the * first letter of the sort key. This parameter does not affect the main * content of the cursor. * * @hide */ public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras"; /** * The array of address book index titles, which are returned in the * same order as the data in the cursor. *TYPE: String[]
* * @hide */ public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles"; /** * The array of group counts for the corresponding group. Contains the same number * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array. *TYPE: int[]
* * @hide */ public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts"; } /** * Constants for the contacts table, which contains a record per aggregate * of raw contacts representing the same person. *Contacts | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Row ID. Consider using {@link #LOOKUP_KEY} instead. | *
String | *{@link #LOOKUP_KEY} | *read-only | *An opaque value that contains hints on how to find the contact if its * row id changed as a result of a sync or aggregation. | *
long | *NAME_RAW_CONTACT_ID | *read-only | *The ID of the raw contact that contributes the display name * to the aggregate contact. During aggregation one of the constituent * raw contacts is chosen using a heuristic: a longer name or a name * with more diacritic marks or more upper case characters is chosen. | *
String | *DISPLAY_NAME_PRIMARY | *read-only | *The display name for the contact. It is the display name * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID * column. | *
long | *{@link #PHOTO_ID} | *read-only | *Reference to the row in the {@link ContactsContract.Data} table holding the photo. * That row has the mime type * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field * is computed automatically based on the * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of * that mime type. | *
int | *{@link #IN_VISIBLE_GROUP} | *read-only | *An indicator of whether this contact is supposed to be visible in the * UI. "1" if the contact has at least one raw contact that belongs to a * visible group; "0" otherwise. | *
int | *{@link #HAS_PHONE_NUMBER} | *read-only | *An indicator of whether this contact has at least one phone number. * "1" if there is at least one phone number, "0" otherwise. | *
int | *{@link #TIMES_CONTACTED} | *read/write | *The number of times the contact has been contacted. See * {@link #markAsContacted}. When raw contacts are aggregated, this field is * computed automatically as the maximum number of times contacted among all * constituent raw contacts. Setting this field automatically changes the * corresponding field on all constituent raw contacts. | *
long | *{@link #LAST_TIME_CONTACTED} | *read/write | *The timestamp of the last time the contact was contacted. See * {@link #markAsContacted}. Setting this field also automatically * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated, * this field is computed automatically as the latest time contacted of all * constituent raw contacts. Setting this field automatically changes the * corresponding field on all constituent raw contacts. | *
int | *{@link #STARRED} | *read/write | *An indicator for favorite contacts: '1' if favorite, '0' otherwise. * When raw contacts are aggregated, this field is automatically computed: * if any constituent raw contacts are starred, then this field is set to * '1'. Setting this field automatically changes the corresponding field on * all constituent raw contacts. | *
String | *{@link #CUSTOM_RINGTONE} | *read/write | *A custom ringtone associated with a contact. Typically this is the * URI returned by an activity launched with the * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent. | *
int | *{@link #SEND_TO_VOICEMAIL} | *read/write | *An indicator of whether calls from this contact should be forwarded * directly to voice mail ('1') or not ('0'). When raw contacts are * aggregated, this field is automatically computed: if all * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set * to '1'. Setting this field automatically changes the corresponding field * on all constituent raw contacts. | *
int | *{@link #CONTACT_PRESENCE} | *read-only | *Contact IM presence status. See {@link StatusUpdates} for individual * status definitions. Automatically computed as the highest presence of all * constituent raw contacts. The provider may choose not to store this value * in persistent storage. The expectation is that presence status will be * updated on a regular basic. | *
String | *{@link #CONTACT_STATUS} | *read-only | *Contact's latest status update. Automatically computed as the latest * of all constituent raw contacts' status updates. | *
long | *{@link #CONTACT_STATUS_TIMESTAMP} | *read-only | *The absolute time in milliseconds when the latest status was * inserted/updated. | *
String | *{@link #CONTACT_STATUS_RES_PACKAGE} | *read-only | *The package containing resources for this status: label and icon. | *
long | *{@link #CONTACT_STATUS_LABEL} | *read-only | *The resource ID of the label describing the source of contact status, * e.g. "Google Talk". This resource is scoped by the * {@link #CONTACT_STATUS_RES_PACKAGE}. | *
long | *{@link #CONTACT_STATUS_ICON} | *read-only | *The resource ID of the icon for the source of contact status. This * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}. | *
* As long as the contact's row ID remains the same, this URI is * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes * as a result of a sync or aggregation, this URI will look up the * contact using indirect information (sync IDs or constituent raw * contacts). *
* Lookup key should be appended unencoded - it is stored in the encoded * form, ready for use in a URI. */ public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, "lookup"); /** * Base {@link Uri} for referencing a single {@link Contacts} entry, * created by appending {@link #LOOKUP_KEY} using * {@link Uri#withAppendedPath(Uri, String)}. Provides * {@link OpenableColumns} columns when queried, or returns the * referenced contact formatted as a vCard when opened through * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. */ public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, "as_vcard"); /** * Base {@link Uri} for referencing multiple {@link Contacts} entry, * created by appending {@link #LOOKUP_KEY} using * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be * encoded and joined with the colon (":") seperator. The resulting string * has to be encoded again. Provides * {@link OpenableColumns} columns when queried, or returns the * referenced contact formatted as a vCard when opened through * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. * * This is private API because we do not have a well-defined way to * specify several entities yet. The format of this Uri might change in the future * or the Uri might be completely removed. * * @hide */ public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, "as_multi_vcard"); /** * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the * requested {@link Contacts} entry. * * @param contactUri A {@link #CONTENT_URI} row, or an existing * {@link #CONTENT_LOOKUP_URI} to attempt refreshing. */ public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) { final Cursor c = resolver.query(contactUri, new String[] { Contacts.LOOKUP_KEY, Contacts._ID }, null, null, null); if (c == null) { return null; } try { if (c.moveToFirst()) { final String lookupKey = c.getString(0); final long contactId = c.getLong(1); return getLookupUri(contactId, lookupKey); } } finally { c.close(); } return null; } /** * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}. */ public static Uri getLookupUri(long contactId, String lookupKey) { return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId); } /** * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI. *
* Returns null if the contact cannot be found. */ public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) { if (lookupUri == null) { return null; } Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null); if (c == null) { return null; } try { if (c.moveToFirst()) { long contactId = c.getLong(0); return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); } } finally { c.close(); } return null; } /** * Mark a contact as having been contacted. This updates the * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED} for the * contact, plus the corresponding values of any associated raw * contacts. * * @param resolver the ContentResolver to use * @param contactId the person who was contacted */ public static void markAsContacted(ContentResolver resolver, long contactId) { Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId); ContentValues values = new ContentValues(); // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified. values.put(LAST_TIME_CONTACTED, System.currentTimeMillis()); resolver.update(uri, values, null, null); } /** * The content:// style URI used for "type-to-filter" functionality on the * {@link #CONTENT_URI} URI. The filter string will be used to match * various parts of the contact name. The filter argument should be passed * as an additional path segment after this URI. */ public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath( CONTENT_URI, "filter"); /** * The content:// style URI for this table joined with useful data from * {@link ContactsContract.Data}, filtered to include only starred contacts * and the most frequently contacted contacts. */ public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath( CONTENT_URI, "strequent"); /** * The content:// style URI used for "type-to-filter" functionality on the * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match * various parts of the contact name. The filter argument should be passed * as an additional path segment after this URI. */ public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath( CONTENT_STREQUENT_URI, "filter"); public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath( CONTENT_URI, "group"); /** * The MIME type of {@link #CONTENT_URI} providing a directory of * people. */ public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact"; /** * The MIME type of a {@link #CONTENT_URI} subdirectory of a single * person. */ public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact"; /** * The MIME type of a {@link #CONTENT_URI} subdirectory of a single * person. */ public static final String CONTENT_VCARD_TYPE = "text/x-vcard"; /** * A sub-directory of a single contact that contains all of the constituent raw contact * {@link ContactsContract.Data} rows. */ public static final class Data implements BaseColumns, DataColumns { /** * no public constructor since this is a utility class */ private Data() {} /** * The directory twig for this sub-table */ public static final String CONTENT_DIRECTORY = "data"; } /** *
* A read-only sub-directory of a single contact aggregate that * contains all aggregation suggestions (other contacts). The * aggregation suggestions are computed based on approximate data * matches with this contact. *
** Note: this query may be expensive! If you need to use it in bulk, * make sure the user experience is acceptable when the query runs for a * long time. *
* Usage example: * *
* Uri uri = Contacts.CONTENT_URI.buildUpon() * .appendEncodedPath(String.valueOf(contactId)) * .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY) * .appendQueryParameter("limit", "3") * .build() * Cursor cursor = getContentResolver().query(suggestionsUri, * new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY}, * null, null, null); ** * */ // TODO: add ContactOptionsColumns, ContactStatusColumns public static final class AggregationSuggestions implements BaseColumns, ContactsColumns { /** * No public constructor since this is a utility class */ private AggregationSuggestions() {} /** * The directory twig for this sub-table. The URI can be followed by an optional * type-to-filter, similar to * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}. */ public static final String CONTENT_DIRECTORY = "suggestions"; } /** * A read-only sub-directory of a single contact that contains * the contact's primary photo. *
* Usage example: * *
* 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; * } ** * *
You should also consider using the convenience method * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri)} *
*/ // TODO: change DataColumns to DataColumnsWithJoins public static final class Photo implements BaseColumns, DataColumns { /** * no public constructor since this is a utility class */ private Photo() {} /** * The directory twig for this sub-table */ public static final String CONTENT_DIRECTORY = "photo"; /** * Thumbnail photo of the raw contact. This is the raw bytes of an image * that could be inflated using {@link android.graphics.BitmapFactory}. ** Type: BLOB * @hide TODO: Unhide in a separate CL */ public static final String PHOTO = DATA15; } /** * Opens an InputStream for the contacts's default photo and returns the * photo as a byte stream. If there is not photo null will be returned. * * @param contactUri the contact whose photo should be used * @return an InputStream of the photo, or null if no photo is present */ public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) { Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); if (photoUri == null) { return null; } Cursor cursor = cr.query(photoUri, new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); try { if (cursor == null || !cursor.moveToNext()) { return null; } byte[] data = cursor.getBlob(0); if (data == null) { return null; } return new ByteArrayInputStream(data); } finally { if (cursor != null) { cursor.close(); } } } } protected interface RawContactsColumns { /** * A reference to the {@link ContactsContract.Contacts#_ID} that this * data belongs to. *
Type: INTEGER
*/ public static final String CONTACT_ID = "contact_id"; /** * Flag indicating that this {@link RawContacts} entry and its children have * been restricted to specific platform apps. *Type: INTEGER (boolean)
* * @hide until finalized in future platform release */ public static final String IS_RESTRICTED = "is_restricted"; /** * The aggregation mode for this contact. *Type: INTEGER
*/ public static final String AGGREGATION_MODE = "aggregation_mode"; /** * The "deleted" flag: "0" by default, "1" if the row has been marked * for deletion. When {@link android.content.ContentResolver#delete} is * called on a raw contact, it is marked for deletion and removed from its * aggregate contact. The sync adaptor deletes the raw contact on the server and * then calls ContactResolver.delete once more, this time passing the * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize * the data removal. *Type: INTEGER
*/ public static final String DELETED = "deleted"; /** * The "name_verified" flag: "1" means that the name fields on this raw * contact can be trusted and therefore should be used for the entire * aggregated contact. ** If an aggregated contact contains more than one raw contact with a * verified name, one of those verified names is chosen at random. * If an aggregated contact contains no verified names, the * name is chosen randomly from the constituent raw contacts. *
** Updating this flag from "0" to "1" automatically resets it to "0" on * all other raw contacts in the same aggregated contact. *
** Sync adapters should only specify a value for this column when * inserting a raw contact and leave it out when doing an update. *
** The default value is "0" *
*Type: INTEGER
* * @hide */ public static final String NAME_VERIFIED = "name_verified"; } /** * Constants for the raw contacts table, which contains one row of contact * information for each person in each synced account. Sync adapters and * contact management apps * are the primary consumers of this API. * ** As soon as a raw contact is inserted or whenever its constituent data * changes, the provider will check if the raw contact matches other * existing raw contacts and if so will aggregate it with those. The * aggregation is reflected in the {@link RawContacts} table by the change of the * {@link #CONTACT_ID} field, which is the reference to the aggregate contact. *
** Changes to the structured name, organization, phone number, email address, * or nickname trigger a re-aggregation. *
** See also {@link AggregationExceptions} for a mechanism to control * aggregation programmatically. *
* ** Raw contacts can be inserted incrementally or in a batch. * The incremental method is more traditional but less efficient. * It should be used * only if no {@link Data} values are available at the time the raw contact is created: *
* ContentValues values = new ContentValues(); * values.put(RawContacts.ACCOUNT_TYPE, accountType); * values.put(RawContacts.ACCOUNT_NAME, accountName); * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); * long rawContactId = ContentUris.parseId(rawContactUri); ** *
* Once {@link Data} values become available, insert those. * For example, here's how you would insert a name: * *
* values.clear(); * values.put(Data.RAW_CONTACT_ID, rawContactId); * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); * values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan"); * getContentResolver().insert(Data.CONTENT_URI, values); ** *
* The batch method is by far preferred. It inserts the raw contact and its * constituent data rows in a single database transaction * and causes at most one aggregation pass. *
* ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); * ... * int rawContactInsertIndex = ops.size(); * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) * .withValue(RawContacts.ACCOUNT_TYPE, accountType) * .withValue(RawContacts.ACCOUNT_NAME, accountName) * .build()); * * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) * .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) * .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan") * .build()); * * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); ** *
* Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)} * to refer to the as-yet-unknown index value of the raw contact inserted in the * first operation. *
* ** Raw contacts can be updated incrementally or in a batch. * Batch mode should be used whenever possible. * The procedures and considerations are analogous to those documented above for inserts. *
When a raw contact is deleted, all of its Data rows as well as StatusUpdates, * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row * itself is also deleted automatically. *
** The invocation of {@code resolver.delete(...)}, does not immediately delete * a raw contacts row. * Instead, it sets the {@link #DELETED} flag on the raw contact and * removes the raw contact from its aggregate contact. * The sync adapter then deletes the raw contact from the server and * finalizes phone-side deletion by calling {@code resolver.delete(...)} * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.
*
Some sync adapters are read-only, meaning that they only sync server-side * changes to the phone, but not the reverse. If one of those raw contacts * is marked for deletion, it will remain on the phone. However it will be * effectively invisible, because it will not be part of any aggregate contact. *
* It is easy to find all raw contacts in a Contact: *
* Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, * new String[]{RawContacts._ID}, * RawContacts.CONTACT_ID + "=?", * new String[]{String.valueOf(contactId)}, null); ** *
* To find raw contacts within a specific account, * you can either put the account name and type in the selection or pass them as query * parameters. The latter approach is preferable, especially when you can reuse the * URI: *
* Uri rawContactUri = RawContacts.URI.buildUpon() * .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName) * .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType) * .build(); * Cursor c1 = getContentResolver().query(rawContactUri, * RawContacts.STARRED + "<>0", null, null, null); * ... * Cursor c2 = getContentResolver().query(rawContactUri, * RawContacts.DELETED + "<>0", null, null, null); ** *
The best way to read a raw contact along with all the data associated with it is * by using the {@link Entity} directory. If the raw contact has data rows, * the Entity cursor will contain a row for each data row. If the raw contact has no * data rows, the cursor will still contain one row with the raw contact-level information. *
* Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); * Cursor c = getContentResolver().query(entityUri, * new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1}, * null, null, null); * try { * while (c.moveToNext()) { * String sourceId = c.getString(0); * if (!c.isNull(1)) { * String mimeType = c.getString(2); * String data = c.getString(3); * ... * } * } * } finally { * c.close(); * } ** *
RawContacts | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Row ID. Sync adapters should try to preserve row IDs during updates. In other words, * it is much better for a sync adapter to update a raw contact rather than to delete and * re-insert it. | *
long | *{@link #CONTACT_ID} | *read-only | *The ID of the row in the {@link ContactsContract.Contacts} table * that this raw contact belongs * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}. | *
int | *{@link #AGGREGATION_MODE} | *read/write | *A mechanism that allows programmatic control of the aggregation process. The allowed * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED} * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}. | *
int | *{@link #DELETED} | *read/write | *The "deleted" flag: "0" by default, "1" if the row has been marked * for deletion. When {@link android.content.ContentResolver#delete} is * called on a raw contact, it is marked for deletion and removed from its * aggregate contact. The sync adaptor deletes the raw contact on the server and * then calls ContactResolver.delete once more, this time passing the * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize * the data removal. | *
int | *{@link #TIMES_CONTACTED} | *read/write | *The number of times the contact has been contacted. To have an effect * on the corresponding value of the aggregate contact, this field * should be set at the time the raw contact is inserted. * After that, this value is typically updated via * {@link ContactsContract.Contacts#markAsContacted}. | *
long | *{@link #LAST_TIME_CONTACTED} | *read/write | *The timestamp of the last time the contact was contacted. To have an effect * on the corresponding value of the aggregate contact, this field * should be set at the time the raw contact is inserted. * After that, this value is typically updated via * {@link ContactsContract.Contacts#markAsContacted}. * | *
int | *{@link #STARRED} | *read/write | *An indicator for favorite contacts: '1' if favorite, '0' otherwise. * Changing this field immediately affects the corresponding aggregate contact: * if any raw contacts in that aggregate contact are starred, then the contact * itself is marked as starred. | *
String | *{@link #CUSTOM_RINGTONE} | *read/write | *A custom ringtone associated with a raw contact. Typically this is the * URI returned by an activity launched with the * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent. * To have an effect on the corresponding value of the aggregate contact, this field * should be set at the time the raw contact is inserted. To set a custom * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE * Contacts.CUSTOM_RINGTONE} * instead. | *
int | *{@link #SEND_TO_VOICEMAIL} | *read/write | *An indicator of whether calls from this raw contact should be forwarded * directly to voice mail ('1') or not ('0'). To have an effect * on the corresponding value of the aggregate contact, this field * should be set at the time the raw contact is inserted. | *
String | *{@link #ACCOUNT_NAME} | *read/write-once | *The name of the account instance to which this row belongs, which when paired with * {@link #ACCOUNT_TYPE} identifies a specific account. * For example, this will be the Gmail address if it is a Google account. * It should be set at the time * the raw contact is inserted and never changed afterwards. | *
String | *{@link #ACCOUNT_TYPE} | *read/write-once | *
* * The type of account to which this row belongs, which when paired with * {@link #ACCOUNT_NAME} identifies a specific account. * It should be set at the time * the raw contact is inserted and never changed afterwards. * ** To ensure uniqueness, new account types should be chosen according to the * Java package naming convention. Thus a Google account is of type "com.google". * * |
*
String | *{@link #SOURCE_ID} | *read/write | *String that uniquely identifies this row to its source account. * Typically it is set at the time the raw contact is inserted and never * changed afterwards. The one notable exception is a new raw contact: it * will have an account name and type, but no source id. This * indicates to the sync adapter that a new contact needs to be created * server-side and its ID stored in the corresponding SOURCE_ID field on * the phone. * | *
int | *{@link #VERSION} | *read-only | *Version number that is updated whenever this row or its related data * changes. This field can be used for optimistic locking of a raw contact. * | *
int | *{@link #DIRTY} | *read/write | *Flag indicating that {@link #VERSION} has changed, and this row needs * to be synchronized by its owning account. The value is set to "1" automatically * whenever the raw contact changes, unless the URI has the * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified. * The sync adapter should always supply this query parameter to prevent * unnecessary synchronization: user changes some data on the server, * the sync adapter updates the contact on the phone (without the * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag, * which triggers a sync to bring the changes to the server. * | *
String | *{@link #SYNC1} | *read/write | *Generic column provided for arbitrary use by sync adapters. * The content provider * stores this information on behalf of the sync adapter but does not * interpret it in any way. * | *
String | *{@link #SYNC2} | *read/write | *Generic column for use by sync adapters. * | *
String | *{@link #SYNC3} | *read/write | *Generic column for use by sync adapters. * | *
String | *{@link #SYNC4} | *read/write | *Generic column for use by sync adapters. * | *
* Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later. * Changes to the raw contact will update the associated aggregate contact but will not * result in any change in how the contact is aggregated. Similar to * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding * {@link Contacts} aggregate. *
** This can be used to postpone aggregation until after a series of updates, for better * performance and/or user experience. *
** Note that changing * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any * subsequent * change to the raw contact's data will. *
*/ public static final int AGGREGATION_MODE_SUSPENDED = 2; /** ** Aggregation mode: never aggregate this raw contact. The raw contact will not * have a corresponding {@link Contacts} aggregate and therefore will not be included in * {@link Contacts} query results. *
** For example, this mode can be used for a raw contact that is marked for deletion while * waiting for the deletion to occur on the server side. *
* * @see #AGGREGATION_MODE_SUSPENDED */ public static final int AGGREGATION_MODE_DISABLED = 3; /** * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} * entry of the given {@link RawContacts} entry. */ public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) { // TODO: use a lighter query by joining rawcontacts with contacts in provider final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY); final Cursor cursor = resolver.query(dataUri, new String[] { RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY }, null, null, null); Uri lookupUri = null; try { if (cursor != null && cursor.moveToFirst()) { final long contactId = cursor.getLong(0); final String lookupKey = cursor.getString(1); return Contacts.getLookupUri(contactId, lookupKey); } } finally { if (cursor != null) cursor.close(); } return lookupUri; } /** * A sub-directory of a single raw contact that contains all of its * {@link ContactsContract.Data} rows. To access this directory * append {@link Data#CONTENT_DIRECTORY} to the contact URI. * * TODO: deprecate in favor of {@link RawContacts.Entity}. */ public static final class Data implements BaseColumns, DataColumns { /** * no public constructor since this is a utility class */ private Data() { } /** * The directory twig for this sub-table */ public static final String CONTENT_DIRECTORY = "data"; } /** ** A sub-directory of a single raw contact that contains all of its * {@link ContactsContract.Data} rows. To access this directory append * {@link #CONTENT_DIRECTORY} to the contact URI. See * {@link RawContactsEntity} for a stand-alone table containing the same * data. *
** Entity has two ID fields: {@link #_ID} for the raw contact * and {@link #DATA_ID} for the data rows. * Entity always contains at least one row, even if there are no * actual data rows. In this case the {@link #DATA_ID} field will be * null. *
** Entity reads all * data for a raw contact in one transaction, to guarantee * consistency. *
*/ public static final class Entity implements BaseColumns, DataColumns { /** * no public constructor since this is a utility class */ private Entity() { } /** * The directory twig for this sub-table */ public static final String CONTENT_DIRECTORY = "entity"; /** * The ID of the data column. The value will be null if this raw contact has no * data rows. *Type: INTEGER
*/ public static final String DATA_ID = "data_id"; } /** * TODO: javadoc * @param cursor * @return */ public static EntityIterator newEntityIterator(Cursor cursor) { return new EntityIteratorImpl(cursor); } private static class EntityIteratorImpl extends CursorEntityIterator { private static final String[] DATA_KEYS = new String[]{ Data.DATA1, Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6, Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11, Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15, Data.SYNC1, Data.SYNC2, Data.SYNC3, Data.SYNC4}; public EntityIteratorImpl(Cursor cursor) { super(cursor); } @Override public android.content.Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException { final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID); final long rawContactId = cursor.getLong(columnRawContactId); // we expect the cursor is already at the row we need to read from ContentValues cv = new ContentValues(); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED); DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED); DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED); android.content.Entity contact = new android.content.Entity(cv); // read data rows until the contact id changes do { if (rawContactId != cursor.getLong(columnRawContactId)) { break; } // add the data to to the contact cv = new ContentValues(); cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID))); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.RES_PACKAGE); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_SUPER_PRIMARY); DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CommonDataKinds.GroupMembership.GROUP_SOURCE_ID); DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION); for (String key : DATA_KEYS) { final int columnIndex = cursor.getColumnIndexOrThrow(key); if (cursor.isNull(columnIndex)) { // don't put anything } else { try { cv.put(key, cursor.getString(columnIndex)); } catch (SQLiteException e) { cv.put(key, cursor.getBlob(columnIndex)); } } // TODO: go back to this version of the code when bug // http://b/issue?id=2306370 is fixed. // if (cursor.isNull(columnIndex)) { // // don't put anything // } else if (cursor.isLong(columnIndex)) { // values.put(key, cursor.getLong(columnIndex)); // } else if (cursor.isFloat(columnIndex)) { // values.put(key, cursor.getFloat(columnIndex)); // } else if (cursor.isString(columnIndex)) { // values.put(key, cursor.getString(columnIndex)); // } else if (cursor.isBlob(columnIndex)) { // values.put(key, cursor.getBlob(columnIndex)); // } } contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv); } while (cursor.moveToNext()); return contact; } } } /** * Social status update columns. * * @see StatusUpdates * @see ContactsContract.Data */ protected interface StatusColumns { /** * Contact's latest presence level. *Type: INTEGER (one of the values below)
*/ public static final String PRESENCE = "mode"; /** * @deprecated use {@link #PRESENCE} */ @Deprecated public static final String PRESENCE_STATUS = PRESENCE; /** * An allowed value of {@link #PRESENCE}. */ int OFFLINE = 0; /** * An allowed value of {@link #PRESENCE}. */ int INVISIBLE = 1; /** * An allowed value of {@link #PRESENCE}. */ int AWAY = 2; /** * An allowed value of {@link #PRESENCE}. */ int IDLE = 3; /** * An allowed value of {@link #PRESENCE}. */ int DO_NOT_DISTURB = 4; /** * An allowed value of {@link #PRESENCE}. */ int AVAILABLE = 5; /** * Contact latest status update. *Type: TEXT
*/ public static final String STATUS = "status"; /** * @deprecated use {@link #STATUS} */ @Deprecated public static final String PRESENCE_CUSTOM_STATUS = STATUS; /** * The absolute time in milliseconds when the latest status was inserted/updated. *Type: NUMBER
*/ public static final String STATUS_TIMESTAMP = "status_ts"; /** * The package containing resources for this status: label and icon. *Type: NUMBER
*/ public static final String STATUS_RES_PACKAGE = "status_res_package"; /** * The resource ID of the label describing the source of the status update, e.g. "Google * Talk". This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. *Type: NUMBER
*/ public static final String STATUS_LABEL = "status_label"; /** * The resource ID of the icon for the source of the status update. * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. *Type: NUMBER
*/ public static final String STATUS_ICON = "status_icon"; /** * Contact's audio/video chat capability level. *Type: INTEGER (one of the values below)
* @hide */ public static final String CHAT_CAPABILITY = "chat_capability"; /** * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can * display a video feed. * @hide */ public static final int CAPABILITY_HAS_VIDEO_PLAYBACK_ONLY = 1; /** * An allowed value of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability. * @hide */ public static final int CAPABILITY_HAS_VOICE = 2; /** * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a * camera that can be used for video chat (e.g. a front-facing camera on a phone). * @hide */ public static final int CAPABILITY_HAS_CAMERA = 4; } /** * Columns in the Data table. * * @see ContactsContract.Data */ protected interface DataColumns { /** * The package name to use when creating {@link Resources} objects for * this data row. This value is only designed for use when building user * interfaces, and should not be used to infer the owner. * * @hide */ public static final String RES_PACKAGE = "res_package"; /** * The MIME type of the item represented by this row. */ public static final String MIMETYPE = "mimetype"; /** * A reference to the {@link RawContacts#_ID} * that this data belongs to. */ public static final String RAW_CONTACT_ID = "raw_contact_id"; /** * Whether this is the primary entry of its kind for the raw contact it belongs to. *Type: INTEGER (if set, non-0 means true)
*/ public static final String IS_PRIMARY = "is_primary"; /** * Whether this is the primary entry of its kind for the aggregate * contact it belongs to. Any data record that is "super primary" must * also be "primary". *Type: INTEGER (if set, non-0 means true)
*/ public static final String IS_SUPER_PRIMARY = "is_super_primary"; /** * The version of this data record. This is a read-only value. The data column is * guaranteed to not change without the version going up. This value is monotonically * increasing. *Type: INTEGER
*/ public static final String DATA_VERSION = "data_version"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA1 = "data1"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA2 = "data2"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA3 = "data3"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA4 = "data4"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA5 = "data5"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA6 = "data6"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA7 = "data7"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA8 = "data8"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA9 = "data9"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA10 = "data10"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA11 = "data11"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA12 = "data12"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA13 = "data13"; /** Generic data column, the meaning is {@link #MIMETYPE} specific */ public static final String DATA14 = "data14"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention, * this field is used to store BLOBs (binary data). */ public static final String DATA15 = "data15"; /** Generic column for use by sync adapters. */ public static final String SYNC1 = "data_sync1"; /** Generic column for use by sync adapters. */ public static final String SYNC2 = "data_sync2"; /** Generic column for use by sync adapters. */ public static final String SYNC3 = "data_sync3"; /** Generic column for use by sync adapters. */ public static final String SYNC4 = "data_sync4"; } /** * Combines all columns returned by {@link ContactsContract.Data} table queries. * * @see ContactsContract.Data */ protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns, RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns, ContactStatusColumns { } /** ** Constants for the data table, which contains data points tied to a raw * contact. Each row of the data table is typically used to store a single * piece of contact * information (such as a phone number) and its * associated metadata (such as whether it is a work or home number). *
** Data is a generic table that can hold any kind of contact data. * The kind of data stored in a given row is specified by the row's * {@link #MIMETYPE} value, which determines the meaning of the * generic columns {@link #DATA1} through * {@link #DATA15}. * For example, if the data kind is * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column * {@link #DATA1} stores the * phone number, but if the data kind is * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1} * stores the email address. * Sync adapters and applications can introduce their own data kinds. *
** ContactsContract defines a small number of pre-defined data kinds, e.g. * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a * convenience, these classes define data kind specific aliases for DATA1 etc. * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as * {@link ContactsContract.Data Data.DATA1}. *
** {@link #DATA1} is an indexed column and should be used for the data element that is * expected to be most frequently used in query selections. For example, in the * case of a row representing email addresses {@link #DATA1} should probably * be used for the email address itself, while {@link #DATA2} etc can be * used for auxiliary information like type of email address. *
*
* By convention, {@link #DATA15} is used for storing BLOBs (binary data). *
** The sync adapter for a given account type must correctly handle every data type * used in the corresponding raw contacts. Otherwise it could result in lost or * corrupted data. *
** Similarly, you should refrain from introducing new kinds of data for an other * party's account types. For example, if you add a data row for * "favorite song" to a raw contact owned by a Google account, it will not * get synced to the server, because the Google sync adapter does not know * how to handle this data kind. Thus new data kinds are typically * introduced along with new account types, i.e. new sync adapters. *
** Data rows can be inserted/updated/deleted using the traditional * {@link ContentResolver#insert}, {@link ContentResolver#update} and * {@link ContentResolver#delete} methods, however the newer mechanism based * on a batch of {@link ContentProviderOperation} will prove to be a better * choice in almost all cases. All operations in a batch are executed in a * single transaction, which ensures that the phone-side and server-side * state of a raw contact are always consistent. Also, the batch-based * approach is far more efficient: not only are the database operations * faster when executed in a single transaction, but also sending a batch of * commands to the content provider saves a lot of time on context switching * between your process and the process in which the content provider runs. *
** The flip side of using batched operations is that a large batch may lock * up the database for a long time preventing other applications from * accessing data and potentially causing ANRs ("Application Not Responding" * dialogs.) *
** To avoid such lockups of the database, make sure to insert "yield points" * in the batch. A yield point indicates to the content provider that before * executing the next operation it can commit the changes that have already * been made, yield to other requests, open another transaction and continue * processing operations. A yield point will not automatically commit the * transaction, but only if there is another request waiting on the * database. Normally a sync adapter should insert a yield point at the * beginning of each raw contact operation sequence in the batch. See * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}. *
** An individual data row can be inserted using the traditional * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows * should always be inserted as a batch. *
** An example of a traditional insert: *
* ContentValues values = new ContentValues(); * values.put(Data.RAW_CONTACT_ID, rawContactId); * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); * values.put(Phone.NUMBER, "1-800-GOOG-411"); * values.put(Phone.TYPE, Phone.TYPE_CUSTOM); * values.put(Phone.LABEL, "free directory assistance"); * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values); **
* The same done using ContentProviderOperations: *
* ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) * .withValue(Data.RAW_CONTACT_ID, rawContactId) * .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) * .withValue(Phone.NUMBER, "1-800-GOOG-411") * .withValue(Phone.TYPE, Phone.TYPE_CUSTOM) * .withValue(Phone.LABEL, "free directory assistance") * .build()); * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); ** *
* Just as with insert, update can be done incrementally or as a batch, * the batch mode being the preferred method: *
* ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) * .withValue(Email.DATA, "somebody@android.com") * .build()); * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); ** *
* Just as with insert and update, deletion can be done either using the * {@link ContentResolver#delete} method or using a ContentProviderOperation: *
* ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI) * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) * .build()); * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); ** *
*
* Cursor c = getContentResolver().query(Data.CONTENT_URI, * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, * Data.CONTACT_ID + "=?" + " AND " * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", * new String[] {String.valueOf(contactId)}, null); ** *
*
* Cursor c = getContentResolver().query(Data.CONTENT_URI, * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, * Data.RAW_CONTACT_ID + "=?" + " AND " * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", * new String[] {String.valueOf(rawContactId)}, null); **
* Many columns are available via a {@link Data#CONTENT_URI} query. For best performance you * should explicitly specify a projection to only those columns that you need. *
*Data | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Row ID. Sync adapter should try to preserve row IDs during updates. In other words, * it would be a bad idea to delete and reinsert a data row. A sync adapter should * always do an update instead. | *
String | *{@link #MIMETYPE} | *read/write-once | *
* The MIME type of the item represented by this row. Examples of common * MIME types are: *
|
*
long | *{@link #RAW_CONTACT_ID} | *read/write-once | *The id of the row in the {@link RawContacts} table that this data belongs to. | *
int | *{@link #IS_PRIMARY} | *read/write | *Whether this is the primary entry of its kind for the raw contact it belongs to. * "1" if true, "0" if false. * | *
int | *{@link #IS_SUPER_PRIMARY} | *read/write | *Whether this is the primary entry of its kind for the aggregate * contact it belongs to. Any data record that is "super primary" must * also be "primary". For example, the super-primary entry may be * interpreted as the default contact value of its kind (for example, * the default phone number to use for the contact). | *
int | *{@link #DATA_VERSION} | *read-only | *The version of this data record. Whenever the data row changes * the version goes up. This value is monotonically increasing. | *
Any type | *
* {@link #DATA1} * {@link #DATA2} * {@link #DATA3} * {@link #DATA4} * {@link #DATA5} * {@link #DATA6} * {@link #DATA7} * {@link #DATA8} * {@link #DATA9} * {@link #DATA10} * {@link #DATA11} * {@link #DATA12} * {@link #DATA13} * {@link #DATA14} * {@link #DATA15} * |
* read/write | *
* * Generic data columns. The meaning of each column is determined by the * {@link #MIMETYPE}. By convention, {@link #DATA15} is used for storing * BLOBs (binary data). * ** Data columns whose meaning is not explicitly defined for a given MIMETYPE * should not be used. There is no guarantee that any sync adapter will * preserve them. Sync adapters themselves should not use such columns either, * but should instead use {@link #SYNC1}-{@link #SYNC4}. * * |
*
Any type | *
* {@link #SYNC1} * {@link #SYNC2} * {@link #SYNC3} * {@link #SYNC4} * |
* read/write | *Generic columns for use by sync adapters. For example, a Photo row * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error) * in SYNC2, server-side version number in SYNC3 and error code in SYNC4. | *
* Some columns from the most recent associated status update are also available * through an implicit join. *
*Join with {@link StatusUpdates} | *|||
---|---|---|---|
int | *{@link #PRESENCE} | *read-only | *IM presence status linked to this data row. Compare with * {@link #CONTACT_PRESENCE}, which contains the contact's presence across * all IM rows. See {@link StatusUpdates} for individual status definitions. * The provider may choose not to store this value * in persistent storage. The expectation is that presence status will be * updated on a regular basic. * | *
String | *{@link #STATUS} | *read-only | *Latest status update linked with this data row. | *
long | *{@link #STATUS_TIMESTAMP} | *read-only | *The absolute time in milliseconds when the latest status was * inserted/updated for this data row. | *
String | *{@link #STATUS_RES_PACKAGE} | *read-only | *The package containing resources for this status: label and icon. | *
long | *{@link #STATUS_LABEL} | *read-only | *The resource ID of the label describing the source of status update linked * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}. | *
long | *{@link #STATUS_ICON} | *read-only | *The resource ID of the icon for the source of the status update linked * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}. | *
* Some columns from the associated raw contact are also available through an * implicit join. The other columns are excluded as uninteresting in this * context. *
* *Join with {@link ContactsContract.RawContacts} | *|||
---|---|---|---|
long | *{@link #CONTACT_ID} | *read-only | *The id of the row in the {@link Contacts} table that this data belongs * to. | *
int | *{@link #AGGREGATION_MODE} | *read-only | *See {@link RawContacts}. | *
int | *{@link #DELETED} | *read-only | *See {@link RawContacts}. | *
* The ID column for the associated aggregated contact table * {@link ContactsContract.Contacts} is available * via the implicit join to the {@link RawContacts} table, see above. * The remaining columns from this table are also * available, through an implicit join. This * facilitates lookup by * the value of a single data element, such as the email address. *
* *Join with {@link ContactsContract.Contacts} | *|||
---|---|---|---|
String | *{@link #LOOKUP_KEY} | *read-only | *See {@link ContactsContract.Contacts} | *
String | *{@link #DISPLAY_NAME} | *read-only | *See {@link ContactsContract.Contacts} | *
long | *{@link #PHOTO_ID} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #IN_VISIBLE_GROUP} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #HAS_PHONE_NUMBER} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #TIMES_CONTACTED} | *read-only | *See {@link ContactsContract.Contacts}. | *
long | *{@link #LAST_TIME_CONTACTED} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #STARRED} | *read-only | *See {@link ContactsContract.Contacts}. | *
String | *{@link #CUSTOM_RINGTONE} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #SEND_TO_VOICEMAIL} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #CONTACT_PRESENCE} | *read-only | *See {@link ContactsContract.Contacts}. | *
String | *{@link #CONTACT_STATUS} | *read-only | *See {@link ContactsContract.Contacts}. | *
long | *{@link #CONTACT_STATUS_TIMESTAMP} | *read-only | *See {@link ContactsContract.Contacts}. | *
String | *{@link #CONTACT_STATUS_RES_PACKAGE} | *read-only | *See {@link ContactsContract.Contacts}. | *
long | *{@link #CONTACT_STATUS_LABEL} | *read-only | *See {@link ContactsContract.Contacts}. | *
long | *{@link #CONTACT_STATUS_ICON} | *read-only | *See {@link ContactsContract.Contacts}. | *
* If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward * Data.CONTENT_URI contains only exportable data. *
** This flag is useful (currently) only for vCard exporter in Contacts app, which * needs to exclude "un-exportable" data from available data to export, while * Contacts app itself has priviledge to access all data including "un-exportable" * ones and providers return all of them regardless of the callers' intention. *
** Type: INTEGER *
* * @hide Maybe available only in Eclair and not really ready for public use. * TODO: remove, or implement this feature completely. As of now (Eclair), * we only use this flag in queryEntities(), not query(). */ public static final String FOR_EXPORT_ONLY = "for_export_only"; /** ** Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} * entry of the given {@link ContactsContract.Data} entry. *
** Returns the Uri for the contact in the first entry returned by * {@link ContentResolver#query(Uri, String[], String, String[], String)} * for the provided {@code dataUri}. If the query returns null or empty * results, silently returns null. *
*/ public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) { final Cursor cursor = resolver.query(dataUri, new String[] { RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY }, null, null, null); Uri lookupUri = null; try { if (cursor != null && cursor.moveToFirst()) { final long contactId = cursor.getLong(0); final String lookupKey = cursor.getString(1); return Contacts.getLookupUri(contactId, lookupKey); } } finally { if (cursor != null) cursor.close(); } return lookupUri; } } /** ** Constants for the raw contacts entities table, which can be thought of as * an outer join of the raw_contacts table with the data table. It is a strictly * read-only table. *
** If a raw contact has data rows, the RawContactsEntity cursor will contain * a one row for each data row. If the raw contact has no data rows, the * cursor will still contain one row with the raw contact-level information * and nulls for data columns. * *
* Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId); * Cursor c = getContentResolver().query(entityUri, * new String[]{ * RawContactsEntity.SOURCE_ID, * RawContactsEntity.DATA_ID, * RawContactsEntity.MIMETYPE, * RawContactsEntity.DATA1 * }, null, null, null); * try { * while (c.moveToNext()) { * String sourceId = c.getString(0); * if (!c.isNull(1)) { * String mimeType = c.getString(2); * String data = c.getString(3); * ... * } * } * } finally { * c.close(); * } ** *
RawContacts | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Raw contact row ID. See {@link RawContacts}. | *
long | *{@link #CONTACT_ID} | *read-only | *See {@link RawContacts}. | *
int | *{@link #AGGREGATION_MODE} | *read-only | *See {@link RawContacts}. | *
int | *{@link #DELETED} | *read-only | *See {@link RawContacts}. | *
Data | *|||
---|---|---|---|
long | *{@link #DATA_ID} | *read-only | *Data row ID. It will be null if the raw contact has no data rows. | *
String | *{@link #MIMETYPE} | *read-only | *See {@link ContactsContract.Data}. | *
int | *{@link #IS_PRIMARY} | *read-only | *See {@link ContactsContract.Data}. | *
int | *{@link #IS_SUPER_PRIMARY} | *read-only | *See {@link ContactsContract.Data}. | *
int | *{@link #DATA_VERSION} | *read-only | *See {@link ContactsContract.Data}. | *
Any type | *
* {@link #DATA1} * {@link #DATA2} * {@link #DATA3} * {@link #DATA4} * {@link #DATA5} * {@link #DATA6} * {@link #DATA7} * {@link #DATA8} * {@link #DATA9} * {@link #DATA10} * {@link #DATA11} * {@link #DATA12} * {@link #DATA13} * {@link #DATA14} * {@link #DATA15} * |
* read-only | *See {@link ContactsContract.Data}. | *
Any type | *
* {@link #SYNC1} * {@link #SYNC2} * {@link #SYNC3} * {@link #SYNC4} * |
* read-only | *See {@link ContactsContract.Data}. | *
Type: INTEGER
* * @hide Maybe available only in Eclair and not really ready for public use. * TODO: remove, or implement this feature completely. As of now (Eclair), * we only use this flag in queryEntities(), not query(). */ public static final String FOR_EXPORT_ONLY = "for_export_only"; /** * The ID of the data column. The value will be null if this raw contact has no data rows. *Type: INTEGER
*/ public static final String DATA_ID = "data_id"; } /** * @see PhoneLookup */ protected interface PhoneLookupColumns { /** * The phone number as the user entered it. *Type: TEXT
*/ public static final String NUMBER = "number"; /** * The type of phone number, for example Home or Work. *Type: INTEGER
*/ public static final String TYPE = "type"; /** * The user defined label for the phone number. *Type: TEXT
*/ public static final String LABEL = "label"; } /** * A table that represents the result of looking up a phone number, for * example for caller ID. To perform a lookup you must append the number you * want to find to {@link #CONTENT_FILTER_URI}. This query is highly * optimized. ** Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,... ** *
PhoneLookup | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Data row ID. | *
String | *{@link #NUMBER} | *read-only | *Phone number. | *
String | *{@link #TYPE} | *read-only | *Phone number type. See {@link CommonDataKinds.Phone}. | *
String | *{@link #LABEL} | *read-only | *Custom label for the phone number. See {@link CommonDataKinds.Phone}. | *
* Columns from the Contacts table are also available through a join. *
*Join with {@link Contacts} | *|||
---|---|---|---|
String | *{@link #LOOKUP_KEY} | *read-only | *See {@link ContactsContract.Contacts} | *
String | *{@link #DISPLAY_NAME} | *read-only | *See {@link ContactsContract.Contacts} | *
long | *{@link #PHOTO_ID} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #IN_VISIBLE_GROUP} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #HAS_PHONE_NUMBER} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #TIMES_CONTACTED} | *read-only | *See {@link ContactsContract.Contacts}. | *
long | *{@link #LAST_TIME_CONTACTED} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #STARRED} | *read-only | *See {@link ContactsContract.Contacts}. | *
String | *{@link #CUSTOM_RINGTONE} | *read-only | *See {@link ContactsContract.Contacts}. | *
int | *{@link #SEND_TO_VOICEMAIL} | *read-only | *See {@link ContactsContract.Contacts}. | *
* Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber)); **/ public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI, "phone_lookup"); /** * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows. * * @hide */ public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup"; } /** * Additional data mixed in with {@link StatusColumns} to link * back to specific {@link ContactsContract.Data#_ID} entries. * * @see StatusUpdates */ protected interface PresenceColumns { /** * Reference to the {@link Data#_ID} entry that owns this presence. *
Type: INTEGER
*/ public static final String DATA_ID = "presence_data_id"; /** * See {@link CommonDataKinds.Im} for a list of defined protocol constants. *Type: NUMBER
*/ public static final String PROTOCOL = "protocol"; /** * Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or * omitted if {@link #PROTOCOL} value is not * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. * *Type: NUMBER
*/ public static final String CUSTOM_PROTOCOL = "custom_protocol"; /** * The IM handle the presence item is for. The handle is scoped to * {@link #PROTOCOL}. *Type: TEXT
*/ public static final String IM_HANDLE = "im_handle"; /** * The IM account for the local user that the presence data came from. *Type: TEXT
*/ public static final String IM_ACCOUNT = "im_account"; } /** ** A status update is linked to a {@link ContactsContract.Data} row and captures * the user's latest status update via the corresponding source, e.g. * "Having lunch" via "Google Talk". *
** There are two ways a status update can be inserted: by explicitly linking * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and * {@link #IM_HANDLE}. There is no difference between insert and update, you can use * either. *
** You cannot use {@link ContentResolver#update} to change a status, but * {@link ContentResolver#insert} will replace the latests status if it already * exists. *
** Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses * for multiple contacts at once. *
* *StatusUpdates | *|||
---|---|---|---|
long | *{@link #DATA_ID} | *read/write | *Reference to the {@link Data#_ID} entry that owns this presence. If this * field is not specified, the provider will attempt to find a data row * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and * {@link #IM_HANDLE} columns. * | *
long | *{@link #PROTOCOL} | *read/write | *See {@link CommonDataKinds.Im} for a list of defined protocol constants. | *
String | *{@link #CUSTOM_PROTOCOL} | *read/write | *Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or * omitted if {@link #PROTOCOL} value is not * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. | *
String | *{@link #IM_HANDLE} | *read/write | *The IM handle the presence item is for. The handle is scoped to * {@link #PROTOCOL}. | *
String | *{@link #IM_ACCOUNT} | *read/write | *The IM account for the local user that the presence data came from. | *
int | *{@link #PRESENCE} | *read/write | *Contact IM presence status. The allowed values are:
* *
|
String | *{@link #STATUS} | *read/write | *Contact's latest status update, e.g. "having toast for breakfast" | *
long | *{@link #STATUS_TIMESTAMP} | *read/write | *The absolute time in milliseconds when the status was * entered by the user. If this value is not provided, the provider will follow * this logic: if there was no prior status update, the value will be left as null. * If there was a prior status update, the provider will default this field * to the current time. | *
String | *{@link #STATUS_RES_PACKAGE} | *read/write | *The package containing resources for this status: label and icon. | *
long | *{@link #STATUS_LABEL} | *read/write | *The resource ID of the label describing the source of contact status, * e.g. "Google Talk". This resource is scoped by the * {@link #STATUS_RES_PACKAGE}. | *
long | *{@link #STATUS_ICON} | *read/write | *The resource ID of the icon for the source of contact status. This * resource is scoped by the {@link #STATUS_RES_PACKAGE}. | *
* This is temporary API, it will need to change when we move to FTS. * * @hide */ public static class SearchSnippetColumns { /** * The ID of the data row that was matched by the filter. * * @hide */ public static final String SNIPPET_DATA_ID = "snippet_data_id"; /** * The type of data that was matched by the filter. * * @hide */ public static final String SNIPPET_MIMETYPE = "snippet_mimetype"; /** * The {@link Data#DATA1} field of the data row that was matched by the filter. * * @hide */ public static final String SNIPPET_DATA1 = "snippet_data1"; /** * The {@link Data#DATA2} field of the data row that was matched by the filter. * * @hide */ public static final String SNIPPET_DATA2 = "snippet_data2"; /** * The {@link Data#DATA3} field of the data row that was matched by the filter. * * @hide */ public static final String SNIPPET_DATA3 = "snippet_data3"; /** * The {@link Data#DATA4} field of the data row that was matched by the filter. * * @hide */ public static final String SNIPPET_DATA4 = "snippet_data4"; } /** * Container for definitions of common data types stored in the {@link ContactsContract.Data} * table. */ public static final class CommonDataKinds { /** * This utility class cannot be instantiated */ private CommonDataKinds() {} /** * The {@link Data#RES_PACKAGE} value for common data that should be * shown using a default style. * * @hide RES_PACKAGE is hidden */ public static final String PACKAGE_COMMON = "common"; /** * The base types that all "Typed" data kinds support. */ public interface BaseTypes { /** * A custom type. The custom label should be supplied by user. */ public static int TYPE_CUSTOM = 0; } /** * Columns common across the specific types. */ protected interface CommonColumns extends BaseTypes { /** * The data for the contact method. *
Type: TEXT
*/ public static final String DATA = DataColumns.DATA1; /** * The type of data, for example Home or Work. *Type: INTEGER
*/ public static final String TYPE = DataColumns.DATA2; /** * The user defined label for the the contact method. *Type: TEXT
*/ public static final String LABEL = DataColumns.DATA3; } /** * A data kind representing the contact's proper name. You can use all * columns defined for {@link ContactsContract.Data} as well as the following aliases. * *Type | Alias | Data column | *|
---|---|---|---|
String | *{@link #DISPLAY_NAME} | *{@link #DATA1} | ** |
String | *{@link #GIVEN_NAME} | *{@link #DATA2} | ** |
String | *{@link #FAMILY_NAME} | *{@link #DATA3} | ** |
String | *{@link #PREFIX} | *{@link #DATA4} | *Common prefixes in English names are "Mr", "Ms", "Dr" etc. | *
String | *{@link #MIDDLE_NAME} | *{@link #DATA5} | ** |
String | *{@link #SUFFIX} | *{@link #DATA6} | *Common suffixes in English names are "Sr", "Jr", "III" etc. | *
String | *{@link #PHONETIC_GIVEN_NAME} | *{@link #DATA7} | *Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana | *
String | *{@link #PHONETIC_MIDDLE_NAME} | *{@link #DATA8} | ** |
String | *{@link #PHONETIC_FAMILY_NAME} | *{@link #DATA9} | ** |
* Type: TEXT */ public static final String DISPLAY_NAME = DATA1; /** * The given name for the contact. *
Type: TEXT
*/ public static final String GIVEN_NAME = DATA2; /** * The family name for the contact. *Type: TEXT
*/ public static final String FAMILY_NAME = DATA3; /** * The contact's honorific prefix, e.g. "Sir" *Type: TEXT
*/ public static final String PREFIX = DATA4; /** * The contact's middle name *Type: TEXT
*/ public static final String MIDDLE_NAME = DATA5; /** * The contact's honorific suffix, e.g. "Jr" */ public static final String SUFFIX = DATA6; /** * The phonetic version of the given name for the contact. *Type: TEXT
*/ public static final String PHONETIC_GIVEN_NAME = DATA7; /** * The phonetic version of the additional name for the contact. *Type: TEXT
*/ public static final String PHONETIC_MIDDLE_NAME = DATA8; /** * The phonetic version of the family name for the contact. *Type: TEXT
*/ public static final String PHONETIC_FAMILY_NAME = DATA9; /** * The style used for combining given/middle/family name into a full name. * See {@link ContactsContract.FullNameStyle}. * * @hide */ public static final String FULL_NAME_STYLE = DATA10; /** * The alphabet used for capturing the phonetic name. * See ContactsContract.PhoneticNameStyle. * @hide */ public static final String PHONETIC_NAME_STYLE = DATA11; } /** *A data kind representing the contact's nickname. For example, for * Bob Parr ("Mr. Incredible"): *
* ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) * .withValue(Data.RAW_CONTACT_ID, rawContactId) * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) * .withValue(StructuredName.DISPLAY_NAME, "Bob Parr") * .build()); * * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) * .withValue(Data.RAW_CONTACT_ID, rawContactId) * .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE) * .withValue(Nickname.NAME, "Mr. Incredible") * .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM) * .withValue(Nickname.LABEL, "Superhero") * .build()); * * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); ** *
* You can use all columns defined for {@link ContactsContract.Data} as well as the * following aliases. *
* *Type | Alias | Data column | *|
---|---|---|---|
String | *{@link #NAME} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *
* Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
* A data kind representing a telephone number. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #NUMBER} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
Type: TEXT
*/ public static final String NUMBER = DATA; /** * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. * @hide */ @Deprecated public static final CharSequence getDisplayLabel(Context context, int type, CharSequence label, CharSequence[] labelArray) { return getTypeLabel(context.getResources(), type, label); } /** * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. * @hide */ @Deprecated public static final CharSequence getDisplayLabel(Context context, int type, CharSequence label) { return getTypeLabel(context.getResources(), type, label); } /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static final int getTypeLabelResource(int type) { switch (type) { case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome; case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile; case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork; case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork; case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome; case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager; case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther; case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback; case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar; case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain; case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn; case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain; case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax; case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio; case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex; case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd; case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile; case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager; case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant; case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms; default: return com.android.internal.R.string.phoneTypeCustom; } } /** * Return a {@link CharSequence} that best describes the given type, * possibly substituting the given {@link #LABEL} value * for {@link #TYPE_CUSTOM}. */ public static final CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) { return label; } else { final int labelRes = getTypeLabelResource(type); return res.getText(labelRes); } } } /** ** A data kind representing an email address. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #DATA} | *{@link #DATA1} | *Email address itself. | *
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
* The content:// style URL for looking up data rows by email address. The * lookup argument, an email address, should be passed as an additional path segment * after this URI. *
*Example: *
* Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email)); * Cursor c = getContentResolver().query(uri, * new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA}, * null, null, null); ** */ public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, "lookup"); /** *
* The content:// style URL for email lookup using a filter. The filter returns * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied * to display names as well as email addresses. The filter argument should be passed * as an additional path segment after this URI. *
*The query in the following example will return "Robert Parr (bob@incredibles.com)" * as well as "Bob Parr (incredible@android.com)". *
* Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob")); * Cursor c = getContentResolver().query(uri, * new String[]{Email.DISPLAY_NAME, Email.DATA}, * null, null, null); ** */ public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, "filter"); /** * The email address. *
Type: TEXT
* @hide TODO: Unhide in a separate CL */ public static final String ADDRESS = DATA1; public static final int TYPE_HOME = 1; public static final int TYPE_WORK = 2; public static final int TYPE_OTHER = 3; public static final int TYPE_MOBILE = 4; /** * The display name for the email address *Type: TEXT
*/ public static final String DISPLAY_NAME = DATA4; /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static final int getTypeLabelResource(int type) { switch (type) { case TYPE_HOME: return com.android.internal.R.string.emailTypeHome; case TYPE_WORK: return com.android.internal.R.string.emailTypeWork; case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther; case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile; default: return com.android.internal.R.string.emailTypeCustom; } } /** * Return a {@link CharSequence} that best describes the given type, * possibly substituting the given {@link #LABEL} value * for {@link #TYPE_CUSTOM}. */ public static final CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { return label; } else { final int labelRes = getTypeLabelResource(type); return res.getText(labelRes); } } } /** ** A data kind representing a postal addresses. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #FORMATTED_ADDRESS} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
String | *{@link #STREET} | *{@link #DATA4} | ** |
String | *{@link #POBOX} | *{@link #DATA5} | *Post Office Box number | *
String | *{@link #NEIGHBORHOOD} | *{@link #DATA6} | ** |
String | *{@link #CITY} | *{@link #DATA7} | ** |
String | *{@link #REGION} | *{@link #DATA8} | ** |
String | *{@link #POSTCODE} | *{@link #DATA9} | ** |
String | *{@link #COUNTRY} | *{@link #DATA10} | ** |
* Type: TEXT */ public static final String FORMATTED_ADDRESS = DATA; /** * Can be street, avenue, road, etc. This element also includes the * house number and room/apartment/flat/floor number. *
* Type: TEXT */ public static final String STREET = DATA4; /** * Covers actual P.O. boxes, drawers, locked bags, etc. This is * usually but not always mutually exclusive with street. *
* Type: TEXT */ public static final String POBOX = DATA5; /** * This is used to disambiguate a street address when a city * contains more than one street with the same name, or to specify a * small place whose mail is routed through a larger postal town. In * China it could be a county or a minor city. *
* Type: TEXT */ public static final String NEIGHBORHOOD = DATA6; /** * Can be city, village, town, borough, etc. This is the postal town * and not necessarily the place of residence or place of business. *
* Type: TEXT */ public static final String CITY = DATA7; /** * A state, province, county (in Ireland), Land (in Germany), * departement (in France), etc. *
* Type: TEXT */ public static final String REGION = DATA8; /** * Postal code. Usually country-wide, but sometimes specific to the * city (e.g. "2" in "Dublin 2, Ireland" addresses). *
* Type: TEXT */ public static final String POSTCODE = DATA9; /** * The name or code of the country. *
* Type: TEXT */ public static final String COUNTRY = DATA10; /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static final int getTypeLabelResource(int type) { switch (type) { case TYPE_HOME: return com.android.internal.R.string.postalTypeHome; case TYPE_WORK: return com.android.internal.R.string.postalTypeWork; case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther; default: return com.android.internal.R.string.postalTypeCustom; } } /** * Return a {@link CharSequence} that best describes the given type, * possibly substituting the given {@link #LABEL} value * for {@link #TYPE_CUSTOM}. */ public static final CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { return label; } else { final int labelRes = getTypeLabelResource(type); return res.getText(labelRes); } } } /** *
* A data kind representing an IM address *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #DATA} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
String | *{@link #PROTOCOL} | *{@link #DATA5} | *
* * Allowed values: *
|
*
String | *{@link #CUSTOM_PROTOCOL} | *{@link #DATA6} | ** |
* A data kind representing an organization. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #COMPANY} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
String | *{@link #TITLE} | *{@link #DATA4} | ** |
String | *{@link #DEPARTMENT} | *{@link #DATA5} | ** |
String | *{@link #JOB_DESCRIPTION} | *{@link #DATA6} | ** |
String | *{@link #SYMBOL} | *{@link #DATA7} | ** |
String | *{@link #PHONETIC_NAME} | *{@link #DATA8} | ** |
String | *{@link #OFFICE_LOCATION} | *{@link #DATA9} | ** |
String | *PHONETIC_NAME_STYLE | *{@link #DATA10} | ** |
Type: TEXT
*/ public static final String COMPANY = DATA; /** * The position title at this company as the user entered it. *Type: TEXT
*/ public static final String TITLE = DATA4; /** * The department at this company as the user entered it. *Type: TEXT
*/ public static final String DEPARTMENT = DATA5; /** * The job description at this company as the user entered it. *Type: TEXT
*/ public static final String JOB_DESCRIPTION = DATA6; /** * The symbol of this company as the user entered it. *Type: TEXT
*/ public static final String SYMBOL = DATA7; /** * The phonetic name of this company as the user entered it. *Type: TEXT
*/ public static final String PHONETIC_NAME = DATA8; /** * The office location of this organization. *Type: TEXT
*/ public static final String OFFICE_LOCATION = DATA9; /** * The alphabet used for capturing the phonetic name. * See {@link ContactsContract.PhoneticNameStyle}. * @hide */ public static final String PHONETIC_NAME_STYLE = DATA10; /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static final int getTypeLabelResource(int type) { switch (type) { case TYPE_WORK: return com.android.internal.R.string.orgTypeWork; case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther; default: return com.android.internal.R.string.orgTypeCustom; } } /** * Return a {@link CharSequence} that best describes the given type, * possibly substituting the given {@link #LABEL} value * for {@link #TYPE_CUSTOM}. */ public static final CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { return label; } else { final int labelRes = getTypeLabelResource(type); return res.getText(labelRes); } } } /** ** A data kind representing a relation. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #NAME} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
Type: TEXT
*/ public static final String NAME = DATA; } /** ** A data kind representing an event. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #START_DATE} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
Type: TEXT
*/ public static final String START_DATE = DATA; /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static int getTypeResource(Integer type) { if (type == null) { return com.android.internal.R.string.eventTypeOther; } switch (type) { case TYPE_ANNIVERSARY: return com.android.internal.R.string.eventTypeAnniversary; case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday; case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther; default: return com.android.internal.R.string.eventTypeOther; } } } /** ** A data kind representing an photo for the contact. *
** Some sync adapters will choose to download photos in a separate * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1} * through {@link ContactsContract.Data#SYNC4} to store temporary * data, e.g. the image URL or ID, state of download, server-side version * of the image. It is allowed for the {@link #PHOTO} to be null. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
BLOB | *{@link #PHOTO} | *{@link #DATA15} | *By convention, binary data is stored in DATA15. | *
* Type: BLOB */ public static final String PHOTO = DATA15; } /** *
* Notes about the contact. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #NOTE} | *{@link #DATA1} | ** |
Type: TEXT
*/ public static final String NOTE = DATA1; } /** ** Group Membership. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
long | *{@link #GROUP_ROW_ID} | *{@link #DATA1} | ** |
String | *{@link #GROUP_SOURCE_ID} | *none | *
* * The sourceid of the group that this group membership refers to. * Exactly one of this or {@link #GROUP_ROW_ID} must be set when * inserting a row. * ** If this field is specified, the provider will first try to * look up a group with this {@link Groups Groups.SOURCE_ID}. If such a group * is found, it will use the corresponding row id. If the group is not * found, it will create one. * |
*
Type: INTEGER
*/ public static final String GROUP_ROW_ID = DATA1; /** * The sourceid of the group that this group membership refers to. Exactly one of * this or {@link #GROUP_ROW_ID} must be set when inserting a row. *Type: TEXT
*/ public static final String GROUP_SOURCE_ID = "group_sourceid"; } /** ** A data kind representing a website related to the contact. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #URL} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
Type: TEXT
*/ public static final String URL = DATA; } /** ** A data kind representing a SIP address for the contact. *
** You can use all columns defined for {@link ContactsContract.Data} as * well as the following aliases. *
*Type | *Alias | Data column | *|
---|---|---|---|
String | *{@link #SIP_ADDRESS} | *{@link #DATA1} | ** |
int | *{@link #TYPE} | *{@link #DATA2} | *Allowed values are:
* *
|
*
String | *{@link #LABEL} | *{@link #DATA3} | ** |
Type: TEXT
*/ public static final String SIP_ADDRESS = DATA1; // ...and TYPE and LABEL come from the CommonColumns interface. /** * Return the string resource that best describes the given * {@link #TYPE}. Will always return a valid resource. */ public static final int getTypeLabelResource(int type) { switch (type) { case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome; case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork; case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther; default: return com.android.internal.R.string.sipAddressTypeCustom; } } /** * Return a {@link CharSequence} that best describes the given type, * possibly substituting the given {@link #LABEL} value * for {@link #TYPE_CUSTOM}. */ public static final CharSequence getTypeLabel(Resources res, int type, CharSequence label) { if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { return label; } else { final int labelRes = getTypeLabelResource(type); return res.getText(labelRes); } } } } /** * @see Groups */ protected interface GroupsColumns { /** * The display title of this group. ** Type: TEXT */ public static final String TITLE = "title"; /** * The package name to use when creating {@link Resources} objects for * this group. This value is only designed for use when building user * interfaces, and should not be used to infer the owner. * * @hide */ public static final String RES_PACKAGE = "res_package"; /** * The display title of this group to load as a resource from * {@link #RES_PACKAGE}, which may be localized. *
Type: TEXT
* * @hide */ public static final String TITLE_RES = "title_res"; /** * Notes about the group. ** Type: TEXT */ public static final String NOTES = "notes"; /** * The ID of this group if it is a System Group, i.e. a group that has a special meaning * to the sync adapter, null otherwise. *
Type: TEXT
*/ public static final String SYSTEM_ID = "system_id"; /** * The total number of {@link Contacts} that have * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only * present when querying {@link Groups#CONTENT_SUMMARY_URI}. ** Type: INTEGER */ public static final String SUMMARY_COUNT = "summ_count"; /** * The total number of {@link Contacts} that have both * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers. * Read-only value that is only present when querying * {@link Groups#CONTENT_SUMMARY_URI}. *
* Type: INTEGER */ public static final String SUMMARY_WITH_PHONES = "summ_phones"; /** * Flag indicating if the contacts belonging to this group should be * visible in any user interface. *
* Type: INTEGER (boolean) */ public static final String GROUP_VISIBLE = "group_visible"; /** * The "deleted" flag: "0" by default, "1" if the row has been marked * for deletion. When {@link android.content.ContentResolver#delete} is * called on a group, it is marked for deletion. The sync adaptor * deletes the group on the server and then calls ContactResolver.delete * once more, this time setting the the * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to * finalize the data removal. *
Type: INTEGER
*/ public static final String DELETED = "deleted"; /** * Whether this group should be synced if the SYNC_EVERYTHING settings * is false for this group's account. ** Type: INTEGER (boolean) */ public static final String SHOULD_SYNC = "should_sync"; } /** * Constants for the groups table. Only per-account groups are supported. *
Groups | *|||
---|---|---|---|
long | *{@link #_ID} | *read-only | *Row ID. Sync adapter should try to preserve row IDs during updates. * In other words, it would be a really bad idea to delete and reinsert a * group. A sync adapter should always do an update instead. | *
String | *{@link #TITLE} | *read/write | *The display title of this group. | *
String | *{@link #NOTES} | *read/write | *Notes about the group. | *
String | *{@link #SYSTEM_ID} | *read/write | *The ID of this group if it is a System Group, i.e. a group that has a * special meaning to the sync adapter, null otherwise. | *
int | *{@link #SUMMARY_COUNT} | *read-only | *The total number of {@link Contacts} that have * {@link CommonDataKinds.GroupMembership} in this group. Read-only value * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}. | *
int | *{@link #SUMMARY_WITH_PHONES} | *read-only | *The total number of {@link Contacts} that have both * {@link CommonDataKinds.GroupMembership} in this group, and also have * phone numbers. Read-only value that is only present when querying * {@link Groups#CONTENT_SUMMARY_URI}. | *
int | *{@link #GROUP_VISIBLE} | *read-only | *Flag indicating if the contacts belonging to this group should be * visible in any user interface. Allowed values: 0 and 1. | *
int | *{@link #DELETED} | *read/write | *The "deleted" flag: "0" by default, "1" if the row has been marked * for deletion. When {@link android.content.ContentResolver#delete} is * called on a group, it is marked for deletion. The sync adaptor deletes * the group on the server and then calls ContactResolver.delete once more, * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER} * query parameter to finalize the data removal. | *
int | *{@link #SHOULD_SYNC} | *read/write | *Whether this group should be synced if the SYNC_EVERYTHING settings * is false for this group's account. | *
* Constants for the contact aggregation exceptions table, which contains * aggregation rules overriding those used by automatic aggregation. This * type only supports query and update. Neither insert nor delete are * supported. *
*AggregationExceptions | *|||
---|---|---|---|
int | *{@link #TYPE} | *read/write | *The type of exception: {@link #TYPE_KEEP_TOGETHER}, * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}. | *
long | *{@link #RAW_CONTACT_ID1} | *read/write | *A reference to the {@link RawContacts#_ID} of the raw contact that * the rule applies to. | *
long | *{@link #RAW_CONTACT_ID2} | *read/write | *A reference to the other {@link RawContacts#_ID} of the raw contact * that the rule applies to. | *
Type: INTEGER
*/ public static final String TYPE = "type"; /** * Allows the provider to automatically decide whether the specified raw contacts should * be included in the same aggregate contact or not. */ public static final int TYPE_AUTOMATIC = 0; /** * Makes sure that the specified raw contacts are included in the same * aggregate contact. */ public static final int TYPE_KEEP_TOGETHER = 1; /** * Makes sure that the specified raw contacts are NOT included in the same * aggregate contact. */ public static final int TYPE_KEEP_SEPARATE = 2; /** * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to. */ public static final String RAW_CONTACT_ID1 = "raw_contact_id1"; /** * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule * applies to. */ public static final String RAW_CONTACT_ID2 = "raw_contact_id2"; } /** * @see Settings */ protected interface SettingsColumns { /** * The name of the account instance to which this row belongs. *Type: TEXT
*/ public static final String ACCOUNT_NAME = "account_name"; /** * The type of account to which this row belongs, which when paired with * {@link #ACCOUNT_NAME} identifies a specific account. *Type: TEXT
*/ public static final String ACCOUNT_TYPE = "account_type"; /** * Depending on the mode defined by the sync-adapter, this flag controls * the top-level sync behavior for this data source. ** Type: INTEGER (boolean) */ public static final String SHOULD_SYNC = "should_sync"; /** * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership} * entries should be visible in any user interface. *
* Type: INTEGER (boolean) */ public static final String UNGROUPED_VISIBLE = "ungrouped_visible"; /** * Read-only flag indicating if this {@link #SHOULD_SYNC} or any * {@link Groups#SHOULD_SYNC} under this account have been marked as * unsynced. */ public static final String ANY_UNSYNCED = "any_unsynced"; /** * Read-only count of {@link Contacts} from a specific source that have * no {@link CommonDataKinds.GroupMembership} entries. *
* Type: INTEGER */ public static final String UNGROUPED_COUNT = "summ_count"; /** * Read-only count of {@link Contacts} from a specific source that have * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers. *
* Type: INTEGER */ public static final String UNGROUPED_WITH_PHONES = "summ_phones"; } /** *
* Contacts-specific settings for various {@link Account}'s. *
*Settings | *|||
---|---|---|---|
String | *{@link #ACCOUNT_NAME} | *read/write-once | *The name of the account instance to which this row belongs. | *
String | *{@link #ACCOUNT_TYPE} | *read/write-once | *The type of account to which this row belongs, which when paired with * {@link #ACCOUNT_NAME} identifies a specific account. | *
int | *{@link #SHOULD_SYNC} | *read/write | *Depending on the mode defined by the sync-adapter, this flag controls * the top-level sync behavior for this data source. | *
int | *{@link #UNGROUPED_VISIBLE} | *read/write | *Flag indicating if contacts without any * {@link CommonDataKinds.GroupMembership} entries should be visible in any * user interface. | *
int | *{@link #ANY_UNSYNCED} | *read-only | *Read-only flag indicating if this {@link #SHOULD_SYNC} or any * {@link Groups#SHOULD_SYNC} under this account have been marked as * unsynced. | *
int | *{@link #UNGROUPED_COUNT} | *read-only | *Read-only count of {@link Contacts} from a specific source that have * no {@link CommonDataKinds.GroupMembership} entries. | *
int | *{@link #UNGROUPED_WITH_PHONES} | *read-only | *Read-only count of {@link Contacts} from a specific source that have * no {@link CommonDataKinds.GroupMembership} entries, and also have phone * numbers. | *
* For mailto:
URIs, the scheme specific portion must be a
* raw email address, such as one built using
* {@link Uri#fromParts(String, String, String)}.
*
* For tel:
URIs, the scheme specific portion is compared
* to existing numbers using the standard caller ID lookup algorithm.
* The number must be properly encoded, for example using
* {@link Uri#fromParts(String, String, String)}.
*
* Any extras from the {@link Insert} class will be passed along to the * create activity if there are no contacts to show. *
* Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip * prompting the user when the contact doesn't exist. */ public static final String SHOW_OR_CREATE_CONTACT = "com.android.contacts.action.SHOW_OR_CREATE_CONTACT"; /** * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new * contact if no matching contact found. Otherwise, default behavior is * to prompt user with dialog before creating. *
* Type: BOOLEAN */ public static final String EXTRA_FORCE_CREATE = "com.android.contacts.action.FORCE_CREATE"; /** * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact * description to be shown when prompting user about creating a new * contact. *
* Type: STRING */ public static final String EXTRA_CREATE_DESCRIPTION = "com.android.contacts.action.CREATE_DESCRIPTION"; /** * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a * dialog location using screen coordinates. When not specified, the * dialog will be centered. * * @hide */ @Deprecated public static final String EXTRA_TARGET_RECT = "target_rect"; /** * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a * desired dialog style, usually a variation on size. One of * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}. * * @hide */ @Deprecated public static final String EXTRA_MODE = "mode"; /** * Value for {@link #EXTRA_MODE} to show a small-sized dialog. * * @hide */ @Deprecated public static final int MODE_SMALL = 1; /** * Value for {@link #EXTRA_MODE} to show a medium-sized dialog. * * @hide */ @Deprecated public static final int MODE_MEDIUM = 2; /** * Value for {@link #EXTRA_MODE} to show a large-sized dialog. * * @hide */ @Deprecated public static final int MODE_LARGE = 3; /** * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate * a list of specific MIME-types to exclude and not display. Stored as a * {@link String} array. * * @hide */ @Deprecated public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes"; /** * Intents related to the Contacts app UI. * * @hide */ public static final class UI { /** * The action for the default contacts list tab. */ public static final String LIST_DEFAULT = "com.android.contacts.action.LIST_DEFAULT"; /** * The action for the contacts list tab. */ public static final String LIST_GROUP_ACTION = "com.android.contacts.action.LIST_GROUP"; /** * When in LIST_GROUP_ACTION mode, this is the group to display. */ public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP"; /** * The action for the all contacts list tab. */ public static final String LIST_ALL_CONTACTS_ACTION = "com.android.contacts.action.LIST_ALL_CONTACTS"; /** * The action for the contacts with phone numbers list tab. */ public static final String LIST_CONTACTS_WITH_PHONES_ACTION = "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES"; /** * The action for the starred contacts list tab. */ public static final String LIST_STARRED_ACTION = "com.android.contacts.action.LIST_STARRED"; /** * The action for the frequent contacts list tab. */ public static final String LIST_FREQUENT_ACTION = "com.android.contacts.action.LIST_FREQUENT"; /** * The action for the "strequent" contacts list tab. It first lists the starred * contacts in alphabetical order and then the frequent contacts in descending * order of the number of times they have been contacted. */ public static final String LIST_STREQUENT_ACTION = "com.android.contacts.action.LIST_STREQUENT"; /** * A key for to be used as an intent extra to set the activity * title to a custom String value. */ public static final String TITLE_EXTRA_KEY = "com.android.contacts.extra.TITLE_EXTRA"; /** * Activity Action: Display a filtered list of contacts *
* Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for * filtering *
* Output: Nothing. */ public static final String FILTER_CONTACTS_ACTION = "com.android.contacts.action.FILTER_CONTACTS"; /** * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION} * intents to supply the text on which to filter. */ public static final String FILTER_TEXT_EXTRA_KEY = "com.android.contacts.extra.FILTER_TEXT"; } /** * Convenience class that contains string constants used * to create contact {@link android.content.Intent Intents}. */ public static final class Insert { /** The action code to use when adding a contact */ public static final String ACTION = Intent.ACTION_INSERT; /** * If present, forces a bypass of quick insert mode. */ public static final String FULL_MODE = "full_mode"; /** * The extra field for the contact name. *
Type: String
*/ public static final String NAME = "name"; // TODO add structured name values here. /** * The extra field for the contact phonetic name. *Type: String
*/ public static final String PHONETIC_NAME = "phonetic_name"; /** * The extra field for the contact company. *Type: String
*/ public static final String COMPANY = "company"; /** * The extra field for the contact job title. *Type: String
*/ public static final String JOB_TITLE = "job_title"; /** * The extra field for the contact notes. *Type: String
*/ public static final String NOTES = "notes"; /** * The extra field for the contact phone number. *Type: String
*/ public static final String PHONE = "phone"; /** * The extra field for the contact phone number type. *Type: Either an integer value from * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String PHONE_TYPE = "phone_type"; /** * The extra field for the phone isprimary flag. *Type: boolean
*/ public static final String PHONE_ISPRIMARY = "phone_isprimary"; /** * The extra field for an optional second contact phone number. *Type: String
*/ public static final String SECONDARY_PHONE = "secondary_phone"; /** * The extra field for an optional second contact phone number type. *Type: Either an integer value from * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type"; /** * The extra field for an optional third contact phone number. *Type: String
*/ public static final String TERTIARY_PHONE = "tertiary_phone"; /** * The extra field for an optional third contact phone number type. *Type: Either an integer value from * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type"; /** * The extra field for the contact email address. *Type: String
*/ public static final String EMAIL = "email"; /** * The extra field for the contact email type. *Type: Either an integer value from * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String EMAIL_TYPE = "email_type"; /** * The extra field for the email isprimary flag. *Type: boolean
*/ public static final String EMAIL_ISPRIMARY = "email_isprimary"; /** * The extra field for an optional second contact email address. *Type: String
*/ public static final String SECONDARY_EMAIL = "secondary_email"; /** * The extra field for an optional second contact email type. *Type: Either an integer value from * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type"; /** * The extra field for an optional third contact email address. *Type: String
*/ public static final String TERTIARY_EMAIL = "tertiary_email"; /** * The extra field for an optional third contact email type. *Type: Either an integer value from * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type"; /** * The extra field for the contact postal address. *Type: String
*/ public static final String POSTAL = "postal"; /** * The extra field for the contact postal address type. *Type: Either an integer value from * {@link CommonDataKinds.StructuredPostal} * or a string specifying a custom label.
*/ public static final String POSTAL_TYPE = "postal_type"; /** * The extra field for the postal isprimary flag. *Type: boolean
*/ public static final String POSTAL_ISPRIMARY = "postal_isprimary"; /** * The extra field for an IM handle. *Type: String
*/ public static final String IM_HANDLE = "im_handle"; /** * The extra field for the IM protocol */ public static final String IM_PROTOCOL = "im_protocol"; /** * The extra field for the IM isprimary flag. *Type: boolean
*/ public static final String IM_ISPRIMARY = "im_isprimary"; } } }