diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 79044018fcf81..c3b0f1c91faa3 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -29,6 +29,7 @@ import android.database.Cursor; import android.graphics.Rect; import android.net.Uri; import android.os.RemoteException; +import android.provider.ContactsContract.CommonDataKinds.Email; import android.text.TextUtils; import android.util.Pair; import android.view.View; @@ -37,8 +38,59 @@ 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}. + *
+ * 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: + *
+ *+ *+ *+ * The {@link Data} table contains all kinds of personal data: phone numbers, + * email addresses etc. The list of data kinds that can be stored in this table + * is open-ended. There is a predefined set of common kinds, but any application + * can add its own data kinds. + *
+ *+ * A row in the {@link RawContacts} table represents a set of Data describing a + * person and associated with a single account. + *
+ *+ * A row in the {@link Contacts} table represents an aggregate of one or more + * RawContacts presumably describing the same person. + *
+ *
+ * Other tables include: + *
+ *+ **/ @SuppressWarnings("unused") public final class ContactsContract { @@ -128,6 +180,9 @@ public final class ContactsContract { * Generic columns for use by sync adapters. The specific functions of * these columns are private to the sync adapter. Other clients of the API * should not attempt to either read or write this column. + * + * @see RawContacts + * @see Groups */ protected interface BaseSyncColumns { @@ -144,6 +199,9 @@ public final class ContactsContract { /** * Columns that appear when each row of a table belongs to a specific * account, including sync information that an account may need. + * + * @see RawContacts + * @see Groups */ protected interface SyncColumns extends BaseSyncColumns { /** @@ -181,6 +239,13 @@ public final class ContactsContract { public static final String DIRTY = "dirty"; } + /** + * @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 @@ -214,6 +279,12 @@ public final class ContactsContract { public static final String SEND_TO_VOICEMAIL = "send_to_voicemail"; } + /** + * @see Contacts + * @see ContactsContract.Data + * @see PhoneLookup + * @see ContactsContract.Contacts.AggregationSuggestions + */ protected interface ContactsColumns { /** * The display name for the contact. @@ -247,6 +318,9 @@ public final class ContactsContract { public static final String LOOKUP_KEY = "lookup"; } + /** + * @see Contacts + */ protected interface ContactStatusColumns { /** * Contact presence status. See {@link StatusUpdates} for individual status @@ -270,7 +344,7 @@ public final class ContactsContract { /** * The package containing resources for this status: label and icon. - *+ * {@link Groups}, which contains information about raw contact groups - the + * current API does not support the notion of groups spanning multiple accounts. + *
+ *+ * {@link StatusUpdates}, which contains social status updates including IM + * availability. + *
+ *+ * {@link AggregationExceptions}, which is used for manual aggregation and + * disaggregation of raw contacts + *
+ *+ * {@link Settings}, which contains visibility and sync settings for accounts + * and groups. + *
+ *+ * {@link SyncState}, which contains free-form data maintained on behalf of sync + * adapters + *
+ *+ * {@link PhoneLookup}, which is used for quick caller-ID lookup + *
Type: NUMBER
+ *Type: TEXT
*/ public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package"; @@ -291,8 +365,194 @@ public final class ContactsContract { } /** - * Constants for the contacts table, which contains a record per group + * 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. | + *
| String | + *{@link #DISPLAY_NAME} | + *read-only | + *The display name for the contact. During aggregation display name is + * computed from display names of constituent raw contacts using a + * heuristic: a longer name or a name with more diacritic marks or more + * upper case characters is chosen. | + *
| 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}. | + *
+ * 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
@@ -495,8 +778,40 @@ public final class ContactsContract {
}
/**
- * A sub-directory of a single contact that contains the contact's primary photo.
+ * 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 @@ -507,6 +822,15 @@ public final class ContactsContract { * 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; } /** @@ -542,7 +866,7 @@ public final class ContactsContract { protected interface RawContactsColumns { /** - * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} that this + * A reference to the {@link ContactsContract.Contacts#_ID} that this * data belongs to. *
Type: INTEGER
*/ @@ -580,6 +904,315 @@ public final class ContactsContract { * Constants for the raw contacts table, which contains the base contact * information per sync source. Sync adapters and contact management apps * are the primary consumers of this API. + *+ * 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 data rows are 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); + *+ * + *
+ * Please note the use of back reference in the construction of the + * {@link ContentProviderOperation}. It allows an operation to use the result of + * a previous operation by referring to it by its index in the batch. + *
+ *Just as with insert, the update can be done incrementally or as a batch, the + * batch mode being the preferred method.
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 in a Contact are deleted, the Contact itself is also deleted automatically. + *
+ *+ * The invocation of {@code resolver.delete(...)}, does not physically delete + * a raw contacts row. 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 #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. + *
+ * Finding all raw contacts in a Contact is easy: + *
+ * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
+ * new String[]{RawContacts._ID},
+ * RawContacts.CONTACT_ID + "=?",
+ * new String[]{String.valueOf(contactId)}, null);
+ *
+ *
+ * + * There are two ways 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();
+ * }
+ *
+ *
+ * + * 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. From the + * data standpoint, aggregation is reflected in the change of the + * {@link #CONTACT_ID} field, which is the reference to the aggregate contact. + *
+ *+ * See also {@link AggregationExceptions} for a mechanism to control + * aggregation programmatically. + *
+ *| RawContacts | + *|||
|---|---|---|---|
| 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 raw contact. A sync adapter should + * always do an update instead. | + *
| long | + *{@link #CONTACT_ID} | + *read-only | + *A reference to the {@link ContactsContract.Contacts#_ID} 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. + * See {@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. + * See {@link ContactsContract.Contacts#markAsContacted}. | + *
| int | + *{@link #STARRED} | + *read/write | + *An indicator for favorite contacts: '1' if favorite, '0' otherwise. + * Changing this field immediately effects 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} + * 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. 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. | + *
| 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 should + * indicated 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 for use by sync adapters. 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. + * | + *
+ * A sub-directory of a single raw contact that contains all of their + * {@link ContactsContract.Data} rows. To access this directory append + * {@link Entity#CONTENT_DIRECTORY} to the contact URI. See + * {@link RawContactsEntity} for a stand-alone table containing the same + * data. + *
+ *+ * The Entity directory is similar to the {@link RawContacts.Data} + * directory but with two important differences: + *
+ * Constants for the data table, which contains data points tied to a raw + * contact. For example, a phone number or email address. + *
+ *+ * Data is a generic table that can hold all kinds of data. Sync adapters + * and applications can introduce their own data kinds. The kind of data + * stored in a particular row is determined by the mime type in the row. + * Fields from {@link #DATA1} through {@link #DATA15} are generic columns + * whose specific use is determined by the kind of data stored in the row. + * For example, if the data kind is + * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then DATA1 stores the + * phone number, but if the data kind is + * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then DATA1 stores the + * email address. + *
+ *+ * ContactsContract defines a small number of common 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). + *
+ *+ * Typically you should refrain from introducing new kinds of data for 3rd + * party 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);
+ *
+ * | 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 rows. 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 | + *A reference to the {@link RawContacts#_ID} that this data belongs to. | + *
| long | + *{@link #CONTACT_ID} | + *read-only | + *A reference to the {@link ContactsContract.Contacts#_ID} that this data row belongs + * to. It is obtained through a join with RawContacts. | + *
| 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". | + *
| 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 is {@link #MIMETYPE} specific. | + *
| 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. | + *
| 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}. | + *
+ * Columns from the associated raw contact are also available through an + * implicit join. + *
+ * + *| Join with {@link RawContacts} | + *|||
|---|---|---|---|
| int | + *{@link #AGGREGATION_MODE} | + *read-only | + *See {@link RawContacts}. | + *
| int | + *{@link #DELETED} | + *read-only | + *See {@link RawContacts}. | + *
+ * Columns from the associated aggregated contact are also available through an + * implicit 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}. | + *
| 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}. | + *
Type: INTEGER
* @@ -872,7 +1997,7 @@ public final class ContactsContract { /** * 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 Data} entry. + * entry of the given {@link ContactsContract.Data} entry. */ public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) { final Cursor cursor = resolver.query(dataUri, new String[] { @@ -894,8 +2019,141 @@ public final class ContactsContract { } /** - * Constants for the raw contacts entities table, which can be though of as an outer join - * of the raw_contacts table with the data table. + *+ * Constants for the raw contacts entities table, which can be though 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}. | + *
+ * 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"); @@ -985,6 +2350,8 @@ public final class ContactsContract { /** * Additional data mixed in with {@link StatusColumns} to link * back to specific {@link ContactsContract.Data#_ID} entries. + * + * @see StatusUpdates */ protected interface PresenceColumns { @@ -995,6 +2362,7 @@ public final class ContactsContract { 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"; @@ -1024,11 +2392,132 @@ public final class ContactsContract { } /** - * A status update is linked to a {@link Data} row and captures the user's latest status - * update via the corresponding source, e.g. "Having lunch" via "Google Talk". + *+ * 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:
+ * + *
+ * Since presence status is inherently volatile, the content provider + * may choose not to store this field in long-term storage. + * + * |
+ *
| 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}. | + *
| 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} | + *+ * |
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} | + *+ * |
+ * 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; @@ -1448,7 +3190,89 @@ public final class ContactsContract { } /** - * Common data definition for postal addresses. + *+ * 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} | + *+ * |
+ * 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} | + *+ * |
+ * 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} | + *+ * |
+ * 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} | + *+ * |
+ * 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. | + *
* 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} | + *+ * |
* 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. + * |
+ *
+ * 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: INTEGER
*/ public static final String DELETED = "deleted"; @@ -2019,7 +4206,82 @@ public final class ContactsContract { } /** - * Constants for the groups table. + * 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. + * 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. | + *
+ * 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. | + *
Type: Either an integer value from - * {@link android.provider.Contacts.PhonesColumns PhonesColumns}, + * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String PHONE_TYPE = "phone_type"; @@ -2613,7 +4968,7 @@ public final class ContactsContract { /** * The extra field for an optional second contact phone number type. *Type: Either an integer value from - * {@link android.provider.Contacts.PhonesColumns PhonesColumns}, + * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type"; @@ -2627,7 +4982,7 @@ public final class ContactsContract { /** * The extra field for an optional third contact phone number type. *Type: Either an integer value from - * {@link android.provider.Contacts.PhonesColumns PhonesColumns}, + * {@link CommonDataKinds.Phone}, * or a string specifying a custom label.
*/ public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type"; @@ -2641,7 +4996,7 @@ public final class ContactsContract { /** * The extra field for the contact email type. *Type: Either an integer value from - * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns} + * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String EMAIL_TYPE = "email_type"; @@ -2661,7 +5016,7 @@ public final class ContactsContract { /** * The extra field for an optional second contact email type. *Type: Either an integer value from - * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns} + * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type"; @@ -2675,7 +5030,7 @@ public final class ContactsContract { /** * The extra field for an optional third contact email type. *Type: Either an integer value from - * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns} + * {@link CommonDataKinds.Email} * or a string specifying a custom label.
*/ public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type"; @@ -2689,7 +5044,7 @@ public final class ContactsContract { /** * The extra field for the contact postal address type. *Type: Either an integer value from - * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns} + * {@link CommonDataKinds.StructuredPostal} * or a string specifying a custom label.
*/ public static final String POSTAL_TYPE = "postal_type";