DocumentsContract | API reference | Android Developers (original) (raw)
public final class DocumentsContractextends [Object](/reference/java/lang/Object) ``
Defines the contract between a documents provider and the platform.
To create a document provider, extend [DocumentsProvider](/reference/android/provider/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[Intent.ACTION_OPEN_DOCUMENT](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT), [Intent.ACTION_CREATE_DOCUMENT](/reference/android/content/Intent#ACTION%5FCREATE%5FDOCUMENT), or [Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE).
Summary
| Nested classes | |
|---|---|
| class | DocumentsContract.Document Constants related to a document, including Cursor column names and flags. |
| class | DocumentsContract.Path Holds a path from a document to a particular document under it. |
| class | DocumentsContract.Root Constants related to a root of documents, including Cursor column names and flags. |
| Constants | |
|---|---|
| String | ACTION_DOCUMENT_SETTINGS Action of intent issued by DocumentsUI when user wishes to open/configure/manage a particular document in the provider application. |
| String | CATEGORY_APPROVED_DOCUMENT_HANDLER Intent category to filter for activities that can handle document intents. |
| String | EXTRA_ERROR Optional string included in a directory Cursor.getExtras() providing an error message that should be shown to a user. |
| 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 Cursor.getExtras() providing an informational message that should be shown to a user. |
| String | EXTRA_INITIAL_URI Sets the desired initial location visible to user when file chooser is shown. |
| String | EXTRA_LOADING Optional boolean flag included in a directory Cursor.getExtras() indicating that a document provider is still loading data. |
| String | EXTRA_ORIENTATION An extra number of degrees that an image should be rotated during the decode process to be presented correctly. |
| String | EXTRA_PROMPT Overrides the default prompt text in DocumentsUI when set in an intent. |
| String | METADATA_EXIF Get Exif information using DocumentsContract#getDocumentMetadata. |
| String | METADATA_TREE_COUNT Get total count of all documents currently stored under the given directory tree. |
| String | METADATA_TREE_SIZE Get total size of all documents currently stored under the given directory tree. |
| String | METADATA_TYPES Get string array identifies the type or types of metadata returned using DocumentsContract#getDocumentMetadata. |
| String | PROVIDER_INTERFACE Intent action used to identify DocumentsProvider instances. |
| String | QUERY_ARG_DISPLAY_NAME Key for DocumentsProvider to query display name is matched. |
| String | QUERY_ARG_EXCLUDE_MEDIA Key for DocumentsProvider to decide whether the files that have been added to MediaStore should be excluded. |
| String | QUERY_ARG_FILE_SIZE_OVER Key for DocumentsProvider to query the file size in bytes is larger than the value. |
| String | QUERY_ARG_LAST_MODIFIED_AFTER Key for DocumentsProvider to query the last modified time is newer than the value. |
| String | QUERY_ARG_MIME_TYPES Key for DocumentsProvider to query mime types is matched. |
| Public methods | |
|---|---|
| staticUri | buildChildDocumentsUri(String authority, String parentDocumentId) Build URI representing the children of the target directory in a document provider. |
| staticUri | buildChildDocumentsUriUsingTree(Uri treeUri, String parentDocumentId) Build URI representing the children of the target directory in a document provider. |
| staticUri | buildDocumentUri(String authority, String documentId) Build URI representing the target Document.COLUMN_DOCUMENT_ID in a document provider. |
| staticUri | buildDocumentUriUsingTree(Uri treeUri, String documentId) Build URI representing the target Document.COLUMN_DOCUMENT_ID in a document provider. |
| staticUri | buildRecentDocumentsUri(String authority, String rootId) Build URI representing the recently modified documents of a specific root in a document provider. |
| staticUri | buildRootUri(String authority, String rootId) Build URI representing the given Root.COLUMN_ROOT_ID in a document provider. |
| staticUri | buildRootsUri(String authority) Build URI representing the roots of a document provider. |
| staticUri | buildSearchDocumentsUri(String authority, String rootId, String query) Build URI representing a search for matching documents under a specific root in a document provider. |
| staticUri | buildTrashDocumentsUri(String authority, String rootId) Returns URI representing the query trash documents of a specific document provider. |
| staticUri | buildTreeDocumentUri(String authority, String documentId) Build URI representing access to descendant documents of the givenDocument.COLUMN_DOCUMENT_ID. |
| staticUri | copyDocument(ContentResolver content, Uri sourceDocumentUri, Uri targetParentDocumentUri) Copies the given document. |
| staticUri | createDocument(ContentResolver content, Uri parentDocumentUri, String mimeType, String displayName) Create a new document with given MIME type and display name. |
| staticIntentSender | createWebLinkIntent(ContentResolver content, Uri uri, Bundle options) Creates an intent for obtaining a web link for the specified document. |
| static boolean | deleteDocument(ContentResolver content, Uri documentUri) Delete the given document. |
| static void | ejectRoot(ContentResolver content, Uri rootUri) Ejects the given root. |
| staticDocumentsContract.Path | findDocumentPath(ContentResolver content, Uri treeUri) Finds the canonical path from the top of the document tree. |
| staticString | getDocumentId(Uri documentUri) Extract the Document.COLUMN_DOCUMENT_ID from the given URI. |
| staticBundle | getDocumentMetadata(ContentResolver content, Uri documentUri) Returns metadata associated with the document. |
| staticBitmap | getDocumentThumbnail(ContentResolver content, Uri documentUri, Point size, CancellationSignal signal) Return thumbnail representing the document at the given URI. |
| staticString | getRootId(Uri rootUri) Extract the Root.COLUMN_ROOT_ID from the given URI. |
| staticString | getSearchDocumentsQuery(Uri searchDocumentsUri) Extract the search query from a URI built bybuildSearchDocumentsUri(String,String,String). |
| staticString | getTreeDocumentId(Uri documentUri) Extract the via Document.COLUMN_DOCUMENT_ID from the given URI. |
| static boolean | isChildDocument(ContentResolver content, Uri parentDocumentUri, Uri childDocumentUri) Test if a document is descendant (child, grandchild, etc) from the given parent. |
| static boolean | isDocumentUri(Context context, Uri uri) Test if the given URI represents a Document backed by aDocumentsProvider. |
| static boolean | isRootUri(Context context, Uri uri) Test if the given URI represents specific root backed by DocumentsProvider. |
| static boolean | isRootsUri(Context context, Uri uri) Test if the given URI represents all roots of the authority backed by DocumentsProvider. |
| static boolean | isTreeUri(Uri uri) Test if the given URI represents a Document tree. |
| staticUri | moveDocument(ContentResolver content, Uri sourceDocumentUri, Uri sourceParentDocumentUri, Uri targetParentDocumentUri) Moves the given document under a new parent. |
| static boolean | removeDocument(ContentResolver content, Uri documentUri, Uri parentDocumentUri) Removes the given document from a parent directory. |
| staticUri | renameDocument(ContentResolver content, Uri documentUri, String displayName) Change the display name of an existing document. |
| staticUri | restoreDocumentFromTrash(ContentResolver content, Uri sourceDocumentUri, Uri targetParentDocumentUri) Restores a document from the trash. |
| staticUri | trashDocument(ContentResolver content, Uri documentUri) Trashes the given document. |
| Inherited methods |
|---|
| From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Constants
ACTION_DOCUMENT_SETTINGS
public static final String ACTION_DOCUMENT_SETTINGS
Action of intent issued by DocumentsUI when user wishes to open/configure/manage a particular document in the provider application.
When issued, the intent will include the URI of the document as the intent data.
A provider wishing to provide support for this action should do two things.
- Add an
<intent-filter>matching this action. - When supplying information in
[DocumentsProvider.queryChildDocuments](/reference/android/provider/DocumentsProvider#queryChildDocuments%28java.lang.String,%20java.lang.String[],%20android.os.Bundle%29), include[Document.FLAG_SUPPORTS_SETTINGS](/reference/android/provider/DocumentsContract.Document#FLAG%5FSUPPORTS%5FSETTINGS)in the flags for each document that supports settings.
Constant Value: "android.provider.action.DOCUMENT_SETTINGS"
CATEGORY_APPROVED_DOCUMENT_HANDLER
public static final String CATEGORY_APPROVED_DOCUMENT_HANDLER
Intent category to filter for activities that can handle document intents.
Indicates that an approved activity can receive intents [Intent.ACTION_SEND](/reference/android/content/Intent#ACTION%5FSEND) and/or[Intent.ACTION_SEND_MULTIPLE](/reference/android/content/Intent#ACTION%5FSEND%5FMULTIPLE). The activity's package must be allowlisted by the system file manager. The activity will appear in the system file manager as a menu item when acceptable files are selected. The activity must also define an `android:label` to be accepted as a menu item.
Optionally, the activity can declare the intent to be shown as an action button instead of a menu item in `AndroidManifest.xml`. It must include an `android:icon` and a meta-data entry `android.approvedtarget.as_button` with a value of `true`.
An example declaration:
<activity android:name=".ApprovedDocumentHandlerActivity" ...
Constant Value: "android.provider.category.APPROVED_DOCUMENT_HANDLER"
public static final String EXTRA_ERROR
Optional string included in a directory [Cursor.getExtras()](/reference/android/database/Cursor#getExtras%28%29) 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"
public static final 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"
public static final String EXTRA_INFO
Optional string included in a directory [Cursor.getExtras()](/reference/android/database/Cursor#getExtras%28%29) 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"
public static final String EXTRA_INITIAL_URI
Sets the desired initial location visible to user when file chooser is shown.
Applicable to [Intent](/reference/android/content/Intent) with actions:
[Intent.ACTION_OPEN_DOCUMENT](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT)[Intent.ACTION_CREATE_DOCUMENT](/reference/android/content/Intent#ACTION%5FCREATE%5FDOCUMENT)[Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE)
Location should specify a document URI or a tree URI with document ID. If this URI identifies a non-directory, document navigator will attempt to use the parent of the document as the initial location.
The initial location is system specific if this extra is missing or document navigator failed to locate the desired initial location.
Constant Value: "android.provider.extra.INITIAL_URI"
public static final String EXTRA_LOADING
Optional boolean flag included in a directory [Cursor.getExtras()](/reference/android/database/Cursor#getExtras%28%29) 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"
public static final String EXTRA_ORIENTATION
An extra number of degrees that an image should be rotated during the decode process to be presented correctly.
Constant Value: "android.provider.extra.ORIENTATION"
public static final String EXTRA_PROMPT
Overrides the default prompt text in DocumentsUI when set in an intent.
Constant Value: "android.provider.extra.PROMPT"
METADATA_EXIF
public static final String METADATA_EXIF
Get Exif information using DocumentsContract#getDocumentMetadata.
Constant Value: "android:documentExif"
METADATA_TREE_COUNT
public static final String METADATA_TREE_COUNT
Get total count of all documents currently stored under the given directory tree. Only valid for [Document.MIME_TYPE_DIR](/reference/android/provider/DocumentsContract.Document#MIME%5FTYPE%5FDIR) documents.
Constant Value: "android:metadataTreeCount"
METADATA_TREE_SIZE
public static final String METADATA_TREE_SIZE
Get total size of all documents currently stored under the given directory tree. Only valid for [Document.MIME_TYPE_DIR](/reference/android/provider/DocumentsContract.Document#MIME%5FTYPE%5FDIR) documents.
Constant Value: "android:metadataTreeSize"
METADATA_TYPES
public static final String METADATA_TYPES
Get string array identifies the type or types of metadata returned using DocumentsContract#getDocumentMetadata.
Constant Value: "android:documentMetadataTypes"
PROVIDER_INTERFACE
public static final String PROVIDER_INTERFACE
Intent action used to identify [DocumentsProvider](/reference/android/provider/DocumentsProvider) instances. This is used in the <intent-filter> of a <provider>.
Constant Value: "android.content.action.DOCUMENTS_PROVIDER"
QUERY_ARG_DISPLAY_NAME
public static final String QUERY_ARG_DISPLAY_NAME
Key for [DocumentsProvider](/reference/android/provider/DocumentsProvider) to query display name is matched. The match of display name is partial matching and case-insensitive. Ex: The value is "o", the display name of the results will contain both "foo" and "Open".
Constant Value: "android:query-arg-display-name"
QUERY_ARG_EXCLUDE_MEDIA
public static final String QUERY_ARG_EXCLUDE_MEDIA
Key for [DocumentsProvider](/reference/android/provider/DocumentsProvider) to decide whether the files that have been added to MediaStore should be excluded. If the value is true, exclude them. Otherwise, include them.
Constant Value: "android:query-arg-exclude-media"
QUERY_ARG_FILE_SIZE_OVER
public static final String QUERY_ARG_FILE_SIZE_OVER
Key for [DocumentsProvider](/reference/android/provider/DocumentsProvider) to query the file size in bytes is larger than the value.
Constant Value: "android:query-arg-file-size-over"
QUERY_ARG_MIME_TYPES
public static final String QUERY_ARG_MIME_TYPES
Key for [DocumentsProvider](/reference/android/provider/DocumentsProvider) to query mime types is matched. The value is a string array, it can support different mime types. Each items will be treated as "OR" condition. Ex: {"image/*" , "video/*"}. The mime types of the results will contain both image type and video type.
Constant Value: "android:query-arg-mime-types"
Public methods
buildChildDocumentsUri
public static 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 [Document](/reference/android/provider/DocumentsContract.Document).
| Parameters | |
|---|---|
| authority | String |
| parentDocumentId | String: the document to return children for, which must be a directory with MIME type ofDocument.MIME_TYPE_DIR. |
| Returns |
|---|
| Uri |
buildChildDocumentsUriUsingTree
public static 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 [Document](/reference/android/provider/DocumentsContract.Document).
However, instead of directly accessing the target directory, the returned URI will leverage access granted through a subtree URI, typically returned by [Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE). 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 Document.MIME_TYPE_DIR. |
| Returns |
|---|
| Uri |
See also:
[Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE)[DocumentsProvider.isChildDocument(String,String)](/reference/android/provider/DocumentsProvider#isChildDocument%28java.lang.String,%20java.lang.String%29)[buildChildDocumentsUri(String,String)](/reference/android/provider/DocumentsContract#buildChildDocumentsUri%28java.lang.String,%20java.lang.String%29)
buildDocumentUri
public static Uri buildDocumentUri (String authority, String documentId)
Build URI representing the target [Document.COLUMN_DOCUMENT_ID](/reference/android/provider/DocumentsContract.Document#COLUMN%5FDOCUMENT%5FID) in a document provider. When queried, a provider will return a single row with columns defined by [Document](/reference/android/provider/DocumentsContract.Document).
| Parameters | |
|---|---|
| authority | String |
| documentId | String |
| Returns |
|---|
| Uri |
buildDocumentUriUsingTree
public static Uri buildDocumentUriUsingTree (Uri treeUri, String documentId)
Build URI representing the target [Document.COLUMN_DOCUMENT_ID](/reference/android/provider/DocumentsContract.Document#COLUMN%5FDOCUMENT%5FID) in a document provider. When queried, a provider will return a single row with columns defined by [Document](/reference/android/provider/DocumentsContract.Document).
However, instead of directly accessing the target document, the returned URI will leverage access granted through a subtree URI, typically returned by [Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE). 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 |
See also:
[Intent.ACTION_OPEN_DOCUMENT_TREE](/reference/android/content/Intent#ACTION%5FOPEN%5FDOCUMENT%5FTREE)[DocumentsProvider.isChildDocument(String,String)](/reference/android/provider/DocumentsProvider#isChildDocument%28java.lang.String,%20java.lang.String%29)[buildDocumentUri(String,String)](/reference/android/provider/DocumentsContract#buildDocumentUri%28java.lang.String,%20java.lang.String%29)
buildRecentDocumentsUri
public static 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 [Document](/reference/android/provider/DocumentsContract.Document).
| Parameters | |
|---|---|
| authority | String |
| rootId | String |
| Returns |
|---|
| Uri |
buildRootUri
public static Uri buildRootUri (String authority, String rootId)
Build URI representing the given [Root.COLUMN_ROOT_ID](/reference/android/provider/DocumentsContract.Root#COLUMN%5FROOT%5FID) in a document provider.
| Parameters | |
|---|---|
| authority | String |
| rootId | String |
| Returns |
|---|
| Uri |
buildRootsUri
public static 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[Root](/reference/android/provider/DocumentsContract.Root).
| Parameters | |
|---|---|
| authority | String |
| Returns |
|---|
| Uri |
buildTreeDocumentUri
public static Uri buildTreeDocumentUri (String authority, String documentId)
Build URI representing access to descendant documents of the given[Document.COLUMN_DOCUMENT_ID](/reference/android/provider/DocumentsContract.Document#COLUMN%5FDOCUMENT%5FID).
| Parameters | |
|---|---|
| authority | String |
| documentId | String |
| Returns |
|---|
| Uri |
copyDocument
public static Uri copyDocument (ContentResolver content, Uri sourceDocumentUri, Uri targetParentDocumentUri)
Copies the given document.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| sourceDocumentUri | Uri: document with Document.FLAG_SUPPORTS_COPY This value cannot be null. |
| targetParentDocumentUri | Uri: document which will become a parent of the source document's copy. This value cannot be null. |
| Returns | |
|---|---|
| Uri | the copied document, or null if failed. |
| Throws |
|---|
| FileNotFoundException |
createDocument
public static Uri createDocument (ContentResolver content, Uri parentDocumentUri, String mimeType, String displayName)
Create a new document with given MIME type and display name.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| parentDocumentUri | Uri: directory with Document.FLAG_DIR_SUPPORTS_CREATE This value cannot be null. |
| mimeType | String: MIME type of new document. This value cannot be null. |
| displayName | String: name of new document. This value cannot be null. |
| Returns | |
|---|---|
| Uri | newly created document, or null if failed |
| Throws |
|---|
| FileNotFoundException |
createWebLinkIntent
public static IntentSender createWebLinkIntent (ContentResolver content, Uri uri, Bundle options)
Creates an intent for obtaining a web link for the specified document.
Note, that due to internal limitations, if there is already a web link intent created for the specified document but with different options, then it may be overridden.
Providers are required to show confirmation UI for all new permissions granted for the linked document.
If list of recipients is known, then it should be passed in options as[Intent.EXTRA_EMAIL](/reference/android/content/Intent#EXTRA%5FEMAIL) as a list of email addresses. Note, that this is just a hint for the provider, which can ignore the list. In either case the provider is required to show a UI for letting the user confirm any new permission grants.
Note, that the entire options bundle will be sent to the provider backing the passed uri. Make sure that you trust the provider before passing any sensitive information.
Since this API may show a UI, it cannot be called from background.
In order to obtain the Web Link use code like this:
void onSomethingHappened() {
IntentSender sender = DocumentsContract.createWebLinkIntent(...);
if (sender != null) {
startIntentSenderForResult(
sender,
WEB_LINK_REQUEST_CODE,
null, 0, 0, 0, null);
}
}
(...)
void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == WEB_LINK_REQUEST_CODE && resultCode == RESULT_OK) {
Uri weblinkUri = data.getData();
...
}
}
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| uri | Uri: uri for the document to create a link to. This value cannot be null. |
| options | Bundle: Extra information for generating the link. This value may be null. |
| Returns | |
|---|---|
| IntentSender | an intent sender to obtain the web link, or null if the document is not linkable, or creating the intent sender failed. |
| Throws |
|---|
| FileNotFoundException |
deleteDocument
public static boolean deleteDocument (ContentResolver content, Uri documentUri)
Delete the given document.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| documentUri | Uri: document with Document.FLAG_SUPPORTS_DELETE This value cannot be null. |
| Returns | |
|---|---|
| boolean | if the document was deleted successfully. |
| Throws |
|---|
| FileNotFoundException |
findDocumentPath
public static DocumentsContract.Path findDocumentPath (ContentResolver content, Uri treeUri)
Finds the canonical path from the top of the document tree. The [Path.getPath()](/reference/android/provider/DocumentsContract.Path#getPath%28%29) of the return value contains the document ID of all documents along the path from the top the document tree to the requested document, both inclusive. The [Path.getRootId()](/reference/android/provider/DocumentsContract.Path#getRootId%28%29) of the return value returns null.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| treeUri | Uri: treeUri of the document which path is requested. This value cannot be null. |
| Returns | |
|---|---|
| DocumentsContract.Path | the path of the document, or null if failed. |
| Throws |
|---|
| FileNotFoundException |
getDocumentMetadata
public static Bundle getDocumentMetadata (ContentResolver content, Uri documentUri)
Returns metadata associated with the document. The type of metadata returned is specific to the document type. For example the data returned for an image file will likely consist primarily or solely of EXIF metadata.
The returned [Bundle](/reference/android/os/Bundle) will contain zero or more entries depending on the type of data supported by the document provider.
- A
[DocumentsContract.METADATA_TYPES](/reference/android/provider/DocumentsContract#METADATA%5FTYPES)containing aString[]value. The string array identifies the type or types of metadata returned. Each value in the can be used to access a[Bundle](/reference/android/os/Bundle)of data containing that type of data. - An entry each for each type of returned metadata. Each set of metadata is itself represented as a bundle and accessible via a string key naming the type of data.
Example:
Bundle metadata = DocumentsContract.getDocumentMetadata(client, imageDocUri, tags);
if (metadata.containsKey(DocumentsContract.METADATA_EXIF)) {
Bundle exif = metadata.getBundle(DocumentsContract.METADATA_EXIF);
int imageLength = exif.getInt(ExifInterface.TAG_IMAGE_LENGTH);
}
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| documentUri | Uri: a Document URI. This value cannot be null. |
| Returns | |
|---|---|
| Bundle | a Bundle of Bundles. This value may be null. |
| Throws |
|---|
| FileNotFoundException |
getDocumentThumbnail
public static Bitmap getDocumentThumbnail (ContentResolver content, 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 | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| documentUri | Uri: document to return thumbnail for, which must haveDocument.FLAG_SUPPORTS_THUMBNAIL set. This value cannot be null. |
| size | Point: optimal thumbnail size desired. A provider may return a thumbnail of a different size, but never more than double the requested size. This value cannot be null. |
| signal | CancellationSignal: signal used to indicate if caller is no longer interested in the thumbnail. This value may be null. |
| Returns | |
|---|---|
| Bitmap | decoded thumbnail, or null if problem was encountered. |
| Throws |
|---|
| FileNotFoundException |
isChildDocument
public static boolean isChildDocument (ContentResolver content, Uri parentDocumentUri, Uri childDocumentUri)
Test if a document is descendant (child, grandchild, etc) from the given parent.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| parentDocumentUri | Uri: parent to verify against. This value cannot be null. |
| childDocumentUri | Uri: child to verify. This value cannot be null. |
| Returns | |
|---|---|
| boolean | if given document is a descendant of the given parent. |
| Throws |
|---|
| FileNotFoundException |
isDocumentUri
public static boolean isDocumentUri (Context context, Uri uri)
Test if the given URI represents a [Document](/reference/android/provider/DocumentsContract.Document) backed by a[DocumentsProvider](/reference/android/provider/DocumentsProvider).
| Parameters | |
|---|---|
| context | Context |
| uri | Uri: This value may be null. |
| Returns |
|---|
| boolean |
isRootUri
public static boolean isRootUri (Context context, Uri uri)
Test if the given URI represents specific root backed by [DocumentsProvider](/reference/android/provider/DocumentsProvider).
| Parameters | |
|---|---|
| context | Context: This value cannot be null. |
| uri | Uri: This value may be null. |
| Returns |
|---|
| boolean |
isRootsUri
public static boolean isRootsUri (Context context, Uri uri)
Test if the given URI represents all roots of the authority backed by [DocumentsProvider](/reference/android/provider/DocumentsProvider).
| Parameters | |
|---|---|
| context | Context: This value cannot be null. |
| uri | Uri: This value may be null. |
| Returns |
|---|
| boolean |
isTreeUri
public static boolean isTreeUri (Uri uri)
Test if the given URI represents a [Document](/reference/android/provider/DocumentsContract.Document) tree.
| Parameters | |
|---|---|
| uri | Uri |
| Returns |
|---|
| boolean |
moveDocument
public static Uri moveDocument (ContentResolver content, Uri sourceDocumentUri, Uri sourceParentDocumentUri, Uri targetParentDocumentUri)
Moves the given document under a new parent.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| sourceDocumentUri | Uri: document with Document.FLAG_SUPPORTS_MOVE This value cannot be null. |
| sourceParentDocumentUri | Uri: parent document of the document to move. This value cannot be null. |
| targetParentDocumentUri | Uri: document which will become a new parent of the source document. This value cannot be null. |
| Returns | |
|---|---|
| Uri | the moved document, or null if failed. |
| Throws |
|---|
| FileNotFoundException |
removeDocument
public static boolean removeDocument (ContentResolver content, Uri documentUri, Uri parentDocumentUri)
Removes the given document from a parent directory.
In contrast to [deleteDocument(ContentResolver, Uri)](/reference/android/provider/DocumentsContract#deleteDocument%28android.content.ContentResolver,%20android.net.Uri%29) it requires specifying the parent. This method is especially useful if the document can be in multiple parents.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| documentUri | Uri: document with Document.FLAG_SUPPORTS_REMOVE This value cannot be null. |
| parentDocumentUri | Uri: parent document of the document to remove. This value cannot be null. |
| Returns | |
|---|---|
| boolean | true if the document was removed successfully. |
| Throws |
|---|
| FileNotFoundException |
renameDocument
public static Uri renameDocument (ContentResolver content, Uri documentUri, String displayName)
Change the display name of an existing document.
If the underlying provider needs to create a new[Document.COLUMN_DOCUMENT_ID](/reference/android/provider/DocumentsContract.Document#COLUMN%5FDOCUMENT%5FID) 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 | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| documentUri | Uri: document with Document.FLAG_SUPPORTS_RENAME This value cannot be null. |
| displayName | String: updated name for document. This value cannot be null. |
| Returns | |
|---|---|
| Uri | the existing or new document after the rename, or null if failed. |
| Throws |
|---|
| FileNotFoundException |
restoreDocumentFromTrash
public static Uri restoreDocumentFromTrash (ContentResolver content, Uri sourceDocumentUri, Uri targetParentDocumentUri)
Restores a document from the trash.
| Parameters | |
|---|---|
| content | ContentResolver: This value cannot be null. |
| sourceDocumentUri | Uri: trashed document to restore. This value cannot be null. |
| targetParentDocumentUri | Uri: parent document to restore the document to. This value may be null. |
| Returns | |
|---|---|
| Uri | the restored document, or null if failed. |
| Throws | |
|---|---|
| FileNotFoundException | if the sourceDocumentUri does not exist or thetargetParentDocumentUri does not exist. |
| IllegalStateException | if the document cannot be restored (e.g., already restored, or original parent is invalid). |
| UnsupportedOperationException | if the document provider does not support restoring. |