DocumentsContract
public
final
class
DocumentsContract
extends Object
| java.lang.Object | |
| ↳ | android.provider.DocumentsContract |
Defines the contract between a documents provider and the platform.
To create a document provider, extend DocumentsProvider, which
provides a foundational implementation of this contract.
All client apps must hold a valid URI permission grant to access documents,
typically issued when a user makes a selection through
ACTION_OPEN_DOCUMENT, ACTION_CREATE_DOCUMENT,
ACTION_OPEN_DOCUMENT_TREE, or
StorageVolume.createAccessIntent.
See also:
Summary
Nested classes | |
|---|---|
class |
DocumentsContract.Document
Constants related to a document, including |
class |
DocumentsContract.Root
Constants related to a root of documents, including |
Constants | |
|---|---|
String |
EXTRA_ERROR
Optional string included in a directory |
String |
EXTRA_EXCLUDE_SELF
Set this in a DocumentsUI intent to cause a package's own roots to be excluded from the roots list. |
String |
EXTRA_INFO
Optional string included in a directory |
String |
EXTRA_LOADING
Optional boolean flag included in a directory |
String |
EXTRA_ORIENTATION
Included in |
String |
EXTRA_PROMPT
Overrides the default prompt text in DocumentsUI when set in an intent. |
String |
PROVIDER_INTERFACE
Intent action used to identify |
Public methods | |
|---|---|
static
Uri
|
buildChildDocumentsUri(String authority, String parentDocumentId)
Build URI representing the children of the target directory in a document provider. |
static
Uri
|
buildChildDocumentsUriUsingTree(Uri treeUri, String parentDocumentId)
Build URI representing the children of the target directory in a document provider. |
static
Uri
|
buildDocumentUri(String authority, String documentId)
Build URI representing the target |
static
Uri
|
buildDocumentUriUsingTree(Uri treeUri, String documentId)
Build URI representing the target |
static
Uri
|
buildRecentDocumentsUri(String authority, String rootId)
Build URI representing the recently modified documents of a specific root in a document provider. |
static
Uri
|
buildRootUri(String authority, String rootId)
Build URI representing the given |
static
Uri
|
buildRootsUri(String authority)
Build URI representing the roots of a document provider. |
static
Uri
|
buildSearchDocumentsUri(String authority, String rootId, String query)
Build URI representing a search for matching documents under a specific root in a document provider. |
static
Uri
|
buildTreeDocumentUri(String authority, String documentId)
Build URI representing access to descendant documents of the given
|
static
Uri
|
copyDocument(ContentResolver resolver, Uri sourceDocumentUri, Uri targetParentDocumentUri)
Copies the given document. |
static
Uri
|
createDocument(ContentResolver resolver, Uri parentDocumentUri, String mimeType, String displayName)
Create a new document with given MIME type and display name. |
static
boolean
|
deleteDocument(ContentResolver resolver, Uri documentUri)
Delete the given document. |
static
String
|
getDocumentId(Uri documentUri)
Extract the |
static
Bitmap
|
getDocumentThumbnail(ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal)
Return thumbnail representing the document at the given URI. |
static
String
|
getRootId(Uri rootUri)
Extract the |
static
String
|
getSearchDocumentsQuery(Uri searchDocumentsUri)
Extract the search query from a URI built by
|
static
String
|
getTreeDocumentId(Uri documentUri)
Extract the via |
static
boolean
|
isDocumentUri(Context context, Uri uri)
Test if the given URI represents a |
static
boolean
|
isTreeUri(Uri uri)
Test if the given URI represents a |
static
Uri
|
moveDocument(ContentResolver resolver, Uri sourceDocumentUri, Uri sourceParentDocumentUri, Uri targetParentDocumentUri)
Moves the given document under a new parent. |
static
boolean
|
removeDocument(ContentResolver resolver, Uri documentUri, Uri parentDocumentUri)
Removes the given document from a parent directory. |
static
Uri
|
renameDocument(ContentResolver resolver, Uri documentUri, String displayName)
Change the display name of an existing document. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
EXTRA_ERROR
String EXTRA_ERROR
Optional string included in a directory getExtras()
providing an error message that should be shown to a user. For example, a
provider may wish to indicate that a network error occurred. The user may
choose to retry, resulting in a new query.
Constant Value: "error"
EXTRA_EXCLUDE_SELF
String EXTRA_EXCLUDE_SELF
Set this in a DocumentsUI intent to cause a package's own roots to be excluded from the roots list.
Constant Value: "android.provider.extra.EXCLUDE_SELF"
EXTRA_INFO
String EXTRA_INFO
Optional string included in a directory getExtras()
providing an informational message that should be shown to a user. For
example, a provider may wish to indicate that not all documents are
available.
Constant Value: "info"
EXTRA_LOADING
String EXTRA_LOADING
Optional boolean flag included in a directory getExtras()
indicating that a document provider is still loading data. For example, a
provider has returned some results, but is still waiting on an
outstanding network request. The provider must send a content changed
notification when loading is finished.
Constant Value: "loading"
EXTRA_ORIENTATION
String EXTRA_ORIENTATION
Included in getExtras() when returned
thumbnail should be rotated.
See also:
Constant Value: "android.provider.extra.ORIENTATION"
EXTRA_PROMPT
String EXTRA_PROMPT
Overrides the default prompt text in DocumentsUI when set in an intent.
Constant Value: "android.provider.extra.PROMPT"
PROVIDER_INTERFACE
String PROVIDER_INTERFACE
Intent action used to identify DocumentsProvider instances. This
is used in the <intent-filter> of a <provider>.
Constant Value: "android.content.action.DOCUMENTS_PROVIDER"
Public methods
buildChildDocumentsUri
Uri buildChildDocumentsUri (String authority, String parentDocumentId)
Build URI representing the children of the target directory in a document
provider. When queried, a provider will return zero or more rows with
columns defined by DocumentsContract.Document.
| Parameters | |
|---|---|
authority |
String
|
parentDocumentId |
String:
the document to return children for, which must
be a directory with MIME type of
MIME_TYPE_DIR. |
| Returns | |
|---|---|
Uri |
|
buildChildDocumentsUriUsingTree
Uri buildChildDocumentsUriUsingTree (Uri treeUri, String parentDocumentId)
Build URI representing the children of the target directory in a document
provider. When queried, a provider will return zero or more rows with
columns defined by DocumentsContract.Document.
However, instead of directly accessing the target directory, the returned
URI will leverage access granted through a subtree URI, typically
returned by ACTION_OPEN_DOCUMENT_TREE. The target
directory must be a descendant (child, grandchild, etc) of the subtree.
This is typically used to access documents under a user-selected directory tree, since it doesn't require the user to separately confirm each new document access.
| Parameters | |
|---|---|
treeUri |
Uri:
the subtree to leverage to gain access to the target
document. The target directory must be a descendant of this
subtree. |
parentDocumentId |
String:
the document to return children for, which the
caller may not have direct access to, and which must be a
directory with MIME type of MIME_TYPE_DIR. |
| Returns | |
|---|---|
Uri |
|
buildDocumentUri
Uri buildDocumentUri (String authority, String documentId)
Build URI representing the target COLUMN_DOCUMENT_ID in
a document provider. When queried, a provider will return a single row
with columns defined by DocumentsContract.Document.
| Parameters | |
|---|---|
authority |
String
|
documentId |
String
|
| Returns | |
|---|---|
Uri |
|
buildDocumentUriUsingTree
Uri buildDocumentUriUsingTree (Uri treeUri, String documentId)
Build URI representing the target COLUMN_DOCUMENT_ID in
a document provider. When queried, a provider will return a single row
with columns defined by DocumentsContract.Document.
However, instead of directly accessing the target document, the returned
URI will leverage access granted through a subtree URI, typically
returned by ACTION_OPEN_DOCUMENT_TREE. The target document
must be a descendant (child, grandchild, etc) of the subtree.
This is typically used to access documents under a user-selected directory tree, since it doesn't require the user to separately confirm each new document access.
| Parameters | |
|---|---|
treeUri |
Uri:
the subtree to leverage to gain access to the target
document. The target directory must be a descendant of this
subtree. |
documentId |
String:
the target document, which the caller may not have
direct access to. |
| Returns | |
|---|---|
Uri |
|
buildRecentDocumentsUri
Uri buildRecentDocumentsUri (String authority, String rootId)
Build URI representing the recently modified documents of a specific root
in a document provider. When queried, a provider will return zero or more
rows with columns defined by DocumentsContract.Document.
| Parameters | |
|---|---|
authority |
String
|
rootId |
String
|
| Returns | |
|---|---|
Uri |
|
buildRootUri
Uri buildRootUri (String authority, String rootId)
Build URI representing the given COLUMN_ROOT_ID in a
document provider.
| Parameters | |
|---|---|
authority |
String
|
rootId |
String
|
| Returns | |
|---|---|
Uri |
|
See also:
buildRootsUri
Uri buildRootsUri (String authority)
Build URI representing the roots of a document provider. When queried, a
provider will return one or more rows with columns defined by
DocumentsContract.Root.
| Parameters | |
|---|---|
authority |
String
|
| Returns | |
|---|---|
Uri |
|
See also:
buildSearchDocumentsUri
Uri buildSearchDocumentsUri (String authority, String rootId, String query)
Build URI representing a search for matching documents under a specific
root in a document provider. When queried, a provider will return zero or
more rows with columns defined by DocumentsContract.Document.
| Parameters | |
|---|---|
authority |
String
|
rootId |
String
|
query |
String
|
| Returns | |
|---|---|
Uri |
|
buildTreeDocumentUri
Uri buildTreeDocumentUri (String authority, String documentId)
Build URI representing access to descendant documents of the given
COLUMN_DOCUMENT_ID.
| Parameters | |
|---|---|
authority |
String
|
documentId |
String
|
| Returns | |
|---|---|
Uri |
|
See also:
copyDocument
Uri copyDocument (ContentResolver resolver, Uri sourceDocumentUri, Uri targetParentDocumentUri)
Copies the given document.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
sourceDocumentUri |
Uri:
document with FLAG_SUPPORTS_COPY |
targetParentDocumentUri |
Uri:
document which will become a parent of the source
document's copy. |
| Returns | |
|---|---|
Uri |
the copied document, or null if failed.
|
createDocument
Uri createDocument (ContentResolver resolver, Uri parentDocumentUri, String mimeType, String displayName)
Create a new document with given MIME type and display name.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
parentDocumentUri |
Uri:
directory with
FLAG_DIR_SUPPORTS_CREATE |
mimeType |
String:
MIME type of new document |
displayName |
String:
name of new document |
| Returns | |
|---|---|
Uri |
newly created document, or null if failed
|
deleteDocument
boolean deleteDocument (ContentResolver resolver, Uri documentUri)
Delete the given document.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
documentUri |
Uri:
document with FLAG_SUPPORTS_DELETE |
| Returns | |
|---|---|
boolean |
if the document was deleted successfully. |
getDocumentId
String getDocumentId (Uri documentUri)
Extract the COLUMN_DOCUMENT_ID from the given URI.
| Parameters | |
|---|---|
documentUri |
Uri
|
| Returns | |
|---|---|
String |
|
See also:
getDocumentThumbnail
Bitmap getDocumentThumbnail (ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal)
Return thumbnail representing the document at the given URI. Callers are responsible for their own in-memory caching.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
documentUri |
Uri:
document to return thumbnail for, which must have
FLAG_SUPPORTS_THUMBNAIL set. |
size |
Point:
optimal thumbnail size desired. A provider may return a
thumbnail of a different size, but never more than double the
requested size. |
signal |
CancellationSignal:
signal used to indicate if caller is no longer interested
in the thumbnail. |
| Returns | |
|---|---|
Bitmap |
decoded thumbnail, or null if problem was encountered. |
getRootId
String getRootId (Uri rootUri)
Extract the COLUMN_ROOT_ID from the given URI.
| Parameters | |
|---|---|
rootUri |
Uri
|
| Returns | |
|---|---|
String |
|
getSearchDocumentsQuery
String getSearchDocumentsQuery (Uri searchDocumentsUri)
Extract the search query from a URI built by
buildSearchDocumentsUri(String, String, String).
| Parameters | |
|---|---|
searchDocumentsUri |
Uri
|
| Returns | |
|---|---|
String |
|
getTreeDocumentId
String getTreeDocumentId (Uri documentUri)
Extract the via COLUMN_DOCUMENT_ID from the given URI.
| Parameters | |
|---|---|
documentUri |
Uri
|
| Returns | |
|---|---|
String |
|
isDocumentUri
boolean isDocumentUri (Context context, Uri uri)
Test if the given URI represents a DocumentsContract.Document backed by a
DocumentsProvider.
| Parameters | |
|---|---|
context |
Context
|
uri |
Uri
|
| Returns | |
|---|---|
boolean |
|
isTreeUri
boolean isTreeUri (Uri uri)
Test if the given URI represents a DocumentsContract.Document tree.
| Parameters | |
|---|---|
uri |
Uri
|
| Returns | |
|---|---|
boolean |
|
moveDocument
Uri moveDocument (ContentResolver resolver, Uri sourceDocumentUri, Uri sourceParentDocumentUri, Uri targetParentDocumentUri)
Moves the given document under a new parent.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
sourceDocumentUri |
Uri:
document with FLAG_SUPPORTS_MOVE |
sourceParentDocumentUri |
Uri:
parent document of the document to move. |
targetParentDocumentUri |
Uri:
document which will become a new parent of the source
document. |
| Returns | |
|---|---|
Uri |
the moved document, or null if failed.
|
removeDocument
boolean removeDocument (ContentResolver resolver, Uri documentUri, Uri parentDocumentUri)
Removes the given document from a parent directory.
In contrast to deleteDocument(ContentResolver, Uri) it requires specifying the parent.
This method is especially useful if the document can be in multiple parents.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
documentUri |
Uri:
document with FLAG_SUPPORTS_REMOVE |
parentDocumentUri |
Uri:
parent document of the document to remove. |
| Returns | |
|---|---|
boolean |
true if the document was removed successfully. |
renameDocument
Uri renameDocument (ContentResolver resolver, Uri documentUri, String displayName)
Change the display name of an existing document.
If the underlying provider needs to create a new
COLUMN_DOCUMENT_ID to represent the updated display
name, that new document is returned and the original document is no
longer valid. Otherwise, the original document is returned.
| Parameters | |
|---|---|
resolver |
ContentResolver
|
documentUri |
Uri:
document with FLAG_SUPPORTS_RENAME |
displayName |
String:
updated name for document |
| Returns | |
|---|---|
Uri |
the existing or new document after the rename, or null if
failed.
|
Interfaces
- BaseColumns
- CalendarContract.AttendeesColumns
- CalendarContract.CalendarAlertsColumns
- CalendarContract.CalendarCacheColumns
- CalendarContract.CalendarColumns
- CalendarContract.CalendarSyncColumns
- CalendarContract.ColorsColumns
- CalendarContract.EventDaysColumns
- CalendarContract.EventsColumns
- CalendarContract.ExtendedPropertiesColumns
- CalendarContract.RemindersColumns
- CalendarContract.SyncColumns
- Contacts.ContactMethodsColumns
- Contacts.ExtensionsColumns
- Contacts.GroupsColumns
- Contacts.OrganizationColumns
- Contacts.PeopleColumns
- Contacts.PhonesColumns
- Contacts.PhotosColumns
- Contacts.PresenceColumns
- Contacts.SettingsColumns
- ContactsContract.BaseSyncColumns
- ContactsContract.CommonDataKinds.BaseTypes
- ContactsContract.CommonDataKinds.CommonColumns
- ContactsContract.ContactNameColumns
- ContactsContract.ContactOptionsColumns
- ContactsContract.ContactsColumns
- ContactsContract.ContactStatusColumns
- ContactsContract.DataColumns
- ContactsContract.DataColumnsWithJoins
- ContactsContract.DataUsageStatColumns
- ContactsContract.DeletedContactsColumns
- ContactsContract.DisplayNameSources
- ContactsContract.FullNameStyle
- ContactsContract.GroupsColumns
- ContactsContract.PhoneLookupColumns
- ContactsContract.PhoneticNameStyle
- ContactsContract.PresenceColumns
- ContactsContract.RawContactsColumns
- ContactsContract.SettingsColumns
- ContactsContract.StatusColumns
- ContactsContract.SyncColumns
- MediaStore.Audio.AlbumColumns
- MediaStore.Audio.ArtistColumns
- MediaStore.Audio.AudioColumns
- MediaStore.Audio.GenresColumns
- MediaStore.Audio.PlaylistsColumns
- MediaStore.Files.FileColumns
- MediaStore.Images.ImageColumns
- MediaStore.MediaColumns
- MediaStore.Video.VideoColumns
- OpenableColumns
- SyncStateContract.Columns
- Telephony.BaseMmsColumns
- Telephony.CanonicalAddressesColumns
- Telephony.TextBasedSmsColumns
- Telephony.ThreadsColumns
Classes
- AlarmClock
- BlockedNumberContract
- BlockedNumberContract.BlockedNumbers
- Browser
- CalendarContract
- CalendarContract.Attendees
- CalendarContract.CalendarAlerts
- CalendarContract.CalendarCache
- CalendarContract.CalendarEntity
- CalendarContract.Calendars
- CalendarContract.Colors
- CalendarContract.EventDays
- CalendarContract.Events
- CalendarContract.EventsEntity
- CalendarContract.ExtendedProperties
- CalendarContract.Instances
- CalendarContract.Reminders
- CalendarContract.SyncState
- CallLog
- CallLog.Calls
- Contacts
- Contacts.ContactMethods
- Contacts.Extensions
- Contacts.GroupMembership
- Contacts.Groups
- Contacts.Intents
- Contacts.Intents.Insert
- Contacts.Intents.UI
- Contacts.Organizations
- Contacts.People
- Contacts.People.ContactMethods
- Contacts.People.Extensions
- Contacts.People.Phones
- Contacts.Phones
- Contacts.Photos
- Contacts.Settings
- ContactsContract
- ContactsContract.AggregationExceptions
- ContactsContract.CommonDataKinds
- ContactsContract.CommonDataKinds.Callable
- ContactsContract.CommonDataKinds.Contactables
- ContactsContract.CommonDataKinds.Email
- ContactsContract.CommonDataKinds.Event
- ContactsContract.CommonDataKinds.GroupMembership
- ContactsContract.CommonDataKinds.Identity
- ContactsContract.CommonDataKinds.Im
- ContactsContract.CommonDataKinds.Nickname
- ContactsContract.CommonDataKinds.Note
- ContactsContract.CommonDataKinds.Organization
- ContactsContract.CommonDataKinds.Phone
- ContactsContract.CommonDataKinds.Photo
- ContactsContract.CommonDataKinds.Relation
- ContactsContract.CommonDataKinds.SipAddress
- ContactsContract.CommonDataKinds.StructuredName
- ContactsContract.CommonDataKinds.StructuredPostal
- ContactsContract.CommonDataKinds.Website
- ContactsContract.Contacts
- ContactsContract.Contacts.AggregationSuggestions
- ContactsContract.Contacts.AggregationSuggestions.Builder
- ContactsContract.Contacts.Data
- ContactsContract.Contacts.Entity
- ContactsContract.Contacts.Photo
- ContactsContract.Data
- ContactsContract.DataUsageFeedback
- ContactsContract.DeletedContacts
- ContactsContract.Directory
- ContactsContract.DisplayPhoto
- ContactsContract.Groups
- ContactsContract.Intents
- ContactsContract.Intents.Insert
- ContactsContract.PhoneLookup
- ContactsContract.PinnedPositions
- ContactsContract.Presence
- ContactsContract.Profile
- ContactsContract.ProfileSyncState
- ContactsContract.ProviderStatus
- ContactsContract.QuickContact
- ContactsContract.RawContacts
- ContactsContract.RawContacts.Data
- ContactsContract.RawContacts.DisplayPhoto
- ContactsContract.RawContacts.Entity
- ContactsContract.RawContactsEntity
- ContactsContract.SearchSnippets
- ContactsContract.Settings
- ContactsContract.StatusUpdates
- ContactsContract.SyncState
- DocumentsContract
- DocumentsContract.Document
- DocumentsContract.Root
- DocumentsProvider
- LiveFolders
- MediaStore
- MediaStore.Audio
- MediaStore.Audio.Albums
- MediaStore.Audio.Artists
- MediaStore.Audio.Artists.Albums
- MediaStore.Audio.Genres
- MediaStore.Audio.Genres.Members
- MediaStore.Audio.Media
- MediaStore.Audio.Playlists
- MediaStore.Audio.Playlists.Members
- MediaStore.Audio.Radio
- MediaStore.Files
- MediaStore.Images
- MediaStore.Images.Media
- MediaStore.Images.Thumbnails
- MediaStore.Video
- MediaStore.Video.Media
- MediaStore.Video.Thumbnails
- SearchRecentSuggestions
- Settings
- Settings.Global
- Settings.NameValueTable
- Settings.Secure
- Settings.System
- SyncStateContract
- SyncStateContract.Constants
- SyncStateContract.Helpers
- Telephony
- Telephony.Carriers
- Telephony.Mms
- Telephony.Mms.Addr
- Telephony.Mms.Draft
- Telephony.Mms.Inbox
- Telephony.Mms.Intents
- Telephony.Mms.Outbox
- Telephony.Mms.Part
- Telephony.Mms.Rate
- Telephony.Mms.Sent
- Telephony.MmsSms
- Telephony.MmsSms.PendingMessages
- Telephony.Sms
- Telephony.Sms.Conversations
- Telephony.Sms.Draft
- Telephony.Sms.Inbox
- Telephony.Sms.Intents
- Telephony.Sms.Outbox
- Telephony.Sms.Sent
- Telephony.Threads
- UserDictionary
- UserDictionary.Words
- VoicemailContract
- VoicemailContract.Status
- VoicemailContract.Voicemails
Exceptions

