ContactsContract.Contacts | API reference | Android Developers
Constants for the contacts table, which contains a record per aggregate of raw contacts representing the same person.
Nested classes
class
ContactsContract.Contacts.AggregationSuggestions
A read-only sub-directory of a single contact aggregate that contains all aggregation suggestions (other contacts).
class
ContactsContract.Contacts.Data
A sub-directory of a single contact that contains all of the constituent raw contact
ContactsContract.Data rows.
class
ContactsContract.Contacts.Entity
A sub-directory of a contact that contains all of its
ContactsContract.RawContacts as well as
ContactsContract.Data rows.
class
ContactsContract.Contacts.Photo
A read-only sub-directory of a single contact that contains the contact's primary photo.
Constants | |
|---|---|
String |
CONTENT_ITEM_TYPE
The MIME type of a |
String |
CONTENT_TYPE
The MIME type of |
String |
CONTENT_VCARD_TYPE
The MIME type of a |
String |
EXTRA_ADDRESS_BOOK_INDEX
Add this query parameter to a URI to get back row counts grouped by the address book index as cursor extras. |
String |
EXTRA_ADDRESS_BOOK_INDEX_COUNTS
The array of group counts for the corresponding group. |
String |
EXTRA_ADDRESS_BOOK_INDEX_TITLES
The array of address book index titles, which are returned in the same order as the data in the cursor. |
String |
QUERY_PARAMETER_VCARD_NO_PHOTO
Boolean parameter that may be used with |
Inherited constants | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
From interface
| ||||||||||||||||||||||||
|
From interface
| ||||||||||||||||||||||||
|
From interface
| ||||||||||||||||||||||||
|
From interface
| ||||||||||||||||||||||||
|
From interface
|
Fields | |
|---|---|
public
static
final
Uri |
CONTENT_FILTER_URI
The content:// style URI used for "type-to-filter" functionality on the
|
public
static
final
Uri |
CONTENT_FREQUENT_URI
This field was deprecated
in API level 29.
Frequent contacts are no longer supported as of
Android version Caution: If you publish your app to the Google Play Store, this field doesn't sort results based on contacts frequency. For more information, see the Contacts Provider page. |
public
static
final
Uri |
CONTENT_GROUP_URI
|
public
static
final
Uri |
CONTENT_LOOKUP_URI
A content:// style URI for this table that should be used to create shortcuts or otherwise create long-term links to contacts. |
public
static
final
Uri |
CONTENT_MULTI_VCARD_URI
Base |
public
static
final
Uri |
CONTENT_STREQUENT_FILTER_URI
The content:// style URI used for "type-to-filter" functionality on the
|
public
static
final
Uri |
CONTENT_STREQUENT_URI
The content:// style URI for this table joined with useful data from
|
public
static
final
Uri |
CONTENT_URI
The content:// style URI for this table |
public
static
final
Uri |
CONTENT_VCARD_URI
Base |
public
static
final
Uri |
ENTERPRISE_CONTENT_FILTER_URI
It supports the similar semantics as |
public
static
final
Uri |
ENTERPRISE_CONTENT_URI
URI used for getting all contacts from both the calling user and the managed profile that is linked to it. |
Public methods | |
|---|---|
static
Uri
|
getLookupUri(ContentResolver resolver, Uri contactUri)
Builds a |
static
Uri
|
getLookupUri(long contactId, String lookupKey)
Build a |
static
boolean
|
isEnterpriseContactId(long contactId)
Return |
static
Uri
|
lookupContact(ContentResolver resolver, Uri lookupUri)
Computes a content URI (see |
static
void
|
markAsContacted(ContentResolver resolver, long contactId)
This method was deprecated
in API level 16.
Contacts affinity information is no longer supported as of
Android version |
static
InputStream
|
openContactPhotoInputStream(ContentResolver cr, Uri contactUri)
Opens an InputStream for the contacts's thumbnail photo and returns the photo as a byte stream. |
static
InputStream
|
openContactPhotoInputStream(ContentResolver cr, Uri contactUri, boolean preferHighres)
Opens an InputStream for the contacts's photo and returns the photo as a byte stream. |
Inherited methods | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
From class
| |||||||||||||||||||||||
Constants
CONTENT_ITEM_TYPE
public static final String CONTENT_ITEM_TYPE
The MIME type of a CONTENT_URI subdirectory of a single
person.
Constant Value: "vnd.android.cursor.item/contact"
CONTENT_TYPE
public static final String CONTENT_TYPE
The MIME type of CONTENT_URI providing a directory of
people.
Constant Value: "vnd.android.cursor.dir/contact"
CONTENT_VCARD_TYPE
public static final String CONTENT_VCARD_TYPE
The MIME type of a CONTENT_URI subdirectory of a single
person.
Constant Value: "text/x-vcard"
EXTRA_ADDRESS_BOOK_INDEX
public static final String EXTRA_ADDRESS_BOOK_INDEX
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.
Example:
import android.provider.ContactsContract.Contacts;
Uri uri = Contacts.CONTENT_URI.buildUpon()
.appendQueryParameter(Contacts.EXTRA_ADDRESS_BOOK_INDEX, "true")
.build();
Cursor cursor = getContentResolver().query(uri,
new String[] {Contacts.DISPLAY_NAME},
null, null, null);
Bundle bundle = cursor.getExtras();
if (bundle.containsKey(Contacts.EXTRA_ADDRESS_BOOK_INDEX_TITLES) &&
bundle.containsKey(Contacts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS)) {
String sections[] =
bundle.getStringArray(Contacts.EXTRA_ADDRESS_BOOK_INDEX_TITLES);
int counts[] = bundle.getIntArray(Contacts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS);
}
Constant Value: "android.provider.extra.ADDRESS_BOOK_INDEX"
EXTRA_ADDRESS_BOOK_INDEX_COUNTS
public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS
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[]
Constant Value: "android.provider.extra.ADDRESS_BOOK_INDEX_COUNTS"
EXTRA_ADDRESS_BOOK_INDEX_TITLES
public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES
The array of address book index titles, which are returned in the same order as the data in the cursor.
TYPE: String[]
Constant Value: "android.provider.extra.ADDRESS_BOOK_INDEX_TITLES"
QUERY_PARAMETER_VCARD_NO_PHOTO
public static final String QUERY_PARAMETER_VCARD_NO_PHOTO
Boolean parameter that may be used with CONTENT_VCARD_URI
and CONTENT_MULTI_VCARD_URI to indicate that the returned
vcard should not contain a photo.
This is useful for obtaining a space efficient vcard.
Constant Value: "no_photo"
Fields
CONTENT_FILTER_URI
public static final Uri CONTENT_FILTER_URI
The content:// style URI used for "type-to-filter" functionality on the
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.
CONTENT_FREQUENT_URI
public static final Uri CONTENT_FREQUENT_URI
This field was deprecated
in API level 29.
Frequent contacts are no longer supported as of
Android version Build.VERSION_CODES.Q.
This URI always returns an empty cursor.
Caution: If you publish your app to the Google Play Store, this field doesn't sort results based on contacts frequency. For more information, see the Contacts Provider page.
The content:// style URI for showing a list of frequently contacted people.
CONTENT_GROUP_URI
public static final Uri CONTENT_GROUP_URI
CONTENT_LOOKUP_URI
public static final Uri CONTENT_LOOKUP_URI
A content:// style URI for this table that should be used to create
shortcuts or otherwise create long-term links to contacts. This URI
should always be followed by a "/" and the contact's ContactsContract.ContactsColumns.LOOKUP_KEY.
It can optionally also have a "/" and last known contact ID appended after
that. This "complete" format is an important optimization and is highly recommended.
As long as the contact's row ID remains the same, this URI is
equivalent to 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.
CONTENT_MULTI_VCARD_URI
public static final Uri CONTENT_MULTI_VCARD_URI
Base Uri for referencing multiple Contacts entry,
created by appending ContactsContract.ContactsColumns.LOOKUP_KEY using
Uri.withAppendedPath(Uri,String). The lookup keys have to be
joined with the colon (":") separator, and the resulting string encoded.
Provides OpenableColumns columns when queried, or returns the
referenced contact formatted as a vCard when opened through
ContentResolver.openAssetFileDescriptor(Uri,String).
Usage example:
- The following code snippet creates a multi-vcard URI that references all the contacts in a user's database.
-
public Uri getAllContactsVcardUri() { Cursor cursor = getActivity().getContentResolver().query(Contacts.CONTENT_URI, new String[] {Contacts.LOOKUP_KEY}, null, null, null); if (cursor == null) { return null; } try { StringBuilder uriListBuilder = new StringBuilder(); int index = 0; while (cursor.moveToNext()) { if (index != 0) uriListBuilder.append(':'); uriListBuilder.append(cursor.getString(0)); index++; } return Uri.withAppendedPath(Contacts.CONTENT_MULTI_VCARD_URI, Uri.encode(uriListBuilder.toString())); } finally { cursor.close(); } }
CONTENT_STREQUENT_FILTER_URI
public static final Uri CONTENT_STREQUENT_FILTER_URI
The content:// style URI used for "type-to-filter" functionality on the
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.
Caution: If you publish your app to the Google Play Store, this field doesn't sort results based on contacts frequency. For more information, see the Contacts Provider page.
CONTENT_STREQUENT_URI
public static final Uri CONTENT_STREQUENT_URI
The content:// style URI for this table joined with useful data from
ContactsContract.Data, filtered to include only starred contacts.
Frequent contacts are no longer included in the result as of
Android version Build.VERSION_CODES.Q.
Caution: If you publish your app to the Google Play Store, this field doesn't sort results based on contacts frequency. For more information, see the Contacts Provider page.
ENTERPRISE_CONTENT_FILTER_URI
public static final Uri ENTERPRISE_CONTENT_FILTER_URI
It supports the similar semantics as CONTENT_FILTER_URI and returns the same
columns. This URI requires ContactsContract.DIRECTORY_PARAM_KEY in parameters,
otherwise it will throw IllegalArgumentException. The passed directory can belong either
to the calling user or to a managed profile that is linked to it.
ENTERPRISE_CONTENT_URI
public static final Uri ENTERPRISE_CONTENT_URI
URI used for getting all contacts from both the calling user and the managed profile that is linked to it.
It supports the same semantics as CONTENT_URI and returns the same columns.
If the calling user has no managed profile, it behaves in the exact same way as
CONTENT_URI.
If there is a managed profile linked to the calling user, it will return merged results
from both.
Note: this query returns the calling user results before the managed profile results, and this order is not affected by the sorting parameter.
If a result is from the managed profile, the following changes are made to the data:
ContactsContract.ContactsColumns.PHOTO_THUMBNAIL_URIandContactsContract.ContactsColumns.PHOTO_URIwill be rewritten to special URIs. UseContentResolver.openAssetFileDescriptoror its siblings to load pictures from them.ContactsContract.ContactsColumns.PHOTO_IDandContactsContract.ContactsColumns.PHOTO_FILE_IDwill be set to null. Don't use them.BaseColumns._IDandContactsContract.ContactsColumns.LOOKUP_KEYwill be replaced with artificial values. These values will be consistent across multiple queries, but do not use them in places that do not explicitly say they accept them. If they are used in theselectionparam inContentProvider.query(Uri, String, Bundle, CancellationSignal), the result is undefined.- In order to tell whether a contact is from the managed profile, use
ContactsContract.Contacts.isEnterpriseContactId(long).
Public methods
isEnterpriseContactId
public static boolean isEnterpriseContactId (long contactId)
Return true if a contact ID is from the contacts provider on the managed profile.
PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI and similar APIs may return such IDs.
| Parameters | |
|---|---|
contactId |
long |
| Returns | |
|---|---|
boolean |
|
lookupContact
public static Uri lookupContact (ContentResolver resolver, Uri lookupUri)
Computes a content URI (see CONTENT_URI) given a lookup URI.
Returns null if the contact cannot be found.
| Parameters | |
|---|---|
resolver |
ContentResolver |
lookupUri |
Uri |
| Returns | |
|---|---|
Uri |
|
markAsContacted
public static void markAsContacted (ContentResolver resolver, long contactId)
This method was deprecated
in API level 16.
Contacts affinity information is no longer supported as of
Android version Build.VERSION_CODES.Q. This method
is no-op.
Mark a contact as having been contacted. Updates two fields:
ContactsContract.ContactOptionsColumns.TIMES_CONTACTED and ContactsContract.ContactOptionsColumns.LAST_TIME_CONTACTED. The
TIMES_CONTACTED field is incremented by 1 and the LAST_TIME_CONTACTED
field is populated with the current system time.
Caution: If you publish your app to the Google Play Store, this field is obsolete, regardless of Android version. For more information, see the Contacts Provider page.
| Parameters | |
|---|---|
resolver |
ContentResolver: the ContentResolver to use |
contactId |
long: the person who was contacted |
openContactPhotoInputStream
public static InputStream openContactPhotoInputStream (ContentResolver cr, Uri contactUri)
Opens an InputStream for the contacts's thumbnail photo and returns the photo as a byte stream.
| Parameters | |
|---|---|
cr |
ContentResolver: The content resolver to use for querying |
contactUri |
Uri: the contact whose photo should be used. This can be used with
either a CONTENT_URI or a CONTENT_LOOKUP_URI URI. |
| Returns | |
|---|---|
InputStream |
an InputStream of the photo, or null if no photo is present |
openContactPhotoInputStream
public static InputStream openContactPhotoInputStream (ContentResolver cr, Uri contactUri, boolean preferHighres)
Opens an InputStream for the contacts's photo and returns the photo as a byte stream.
| Parameters | |
|---|---|
cr |
ContentResolver: The content resolver to use for querying |
contactUri |
Uri: the contact whose photo should be used. This can be used with
either a CONTENT_URI or a CONTENT_LOOKUP_URI URI. |
preferHighres |
boolean: If this is true and the contact has a higher resolution photo
available, it is returned. If false, this function always tries to get the thumbnail |
| Returns | |
|---|---|
InputStream |
an InputStream of the photo, or null if no photo is present |