DocumentsContractCompat

Added in 1.7.0

public final class DocumentsContractCompat


Helper for accessing features in DocumentsContract.

Summary

Nested types

Helper for accessing features in DocumentsContract.Document.

Public methods

static @Nullable Uri
buildChildDocumentsUri(
    @NonNull String authority,
    @Nullable String parentDocumentId
)

Build URI representing the children of the target directory in a document provider.

static @Nullable Uri
buildChildDocumentsUriUsingTree(
    @NonNull Uri treeUri,
    @NonNull String parentDocumentId
)

Build URI representing the children of the target directory in a document provider.

static @Nullable Uri
buildDocumentUri(@NonNull String authority, @NonNull String documentId)

Build URI representing the target COLUMN_DOCUMENT_ID in a document provider.

static @Nullable Uri

Build URI representing the target COLUMN_DOCUMENT_ID in a document provider.

static @Nullable Uri
buildTreeDocumentUri(@NonNull String authority, @NonNull String documentId)

Build URI representing access to descendant documents of the given COLUMN_DOCUMENT_ID.

static @Nullable Uri
createDocument(
    @NonNull ContentResolver content,
    @NonNull Uri parentDocumentUri,
    @NonNull String mimeType,
    @NonNull String displayName
)

Create a new document with given MIME type and display name.

static @Nullable String
getDocumentId(@NonNull Uri documentUri)

Extract the COLUMN_DOCUMENT_ID from the given URI.

static @Nullable String

Extract the via COLUMN_DOCUMENT_ID from the given URI.

static boolean

Checks if the given URI represents a Document backed by a DocumentsProvider.

static boolean

Checks if the given URI represents a Document tree.

static boolean
removeDocument(
    @NonNull ContentResolver content,
    @NonNull Uri documentUri,
    @NonNull Uri parentDocumentUri
)

Removes the given document from a parent directory.

static @Nullable Uri
renameDocument(
    @NonNull ContentResolver content,
    @NonNull Uri documentUri,
    @NonNull String displayName
)

Change the display name of an existing document.

Public methods

buildChildDocumentsUri

Added in 1.7.0
public static @Nullable Uri buildChildDocumentsUri(
    @NonNull String authority,
    @Nullable 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.

buildChildDocumentsUriUsingTree

Added in 1.7.0
public static @Nullable Uri buildChildDocumentsUriUsingTree(
    @NonNull Uri treeUri,
    @NonNull 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.

buildDocumentUri

Added in 1.7.0
public static @Nullable Uri buildDocumentUri(@NonNull String authority, @NonNull 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 Document.

See also
buildDocumentUri

buildDocumentUriUsingTree

Added in 1.7.0
public static @Nullable Uri buildDocumentUriUsingTree(@NonNull Uri treeUri, @NonNull 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 Document.

buildTreeDocumentUri

Added in 1.7.0
public static @Nullable Uri buildTreeDocumentUri(@NonNull String authority, @NonNull String documentId)

Build URI representing access to descendant documents of the given COLUMN_DOCUMENT_ID.

createDocument

Added in 1.7.0
public static @Nullable Uri createDocument(
    @NonNull ContentResolver content,
    @NonNull Uri parentDocumentUri,
    @NonNull String mimeType,
    @NonNull String displayName
)

Create a new document with given MIME type and display name.

Parameters
@NonNull ContentResolver content

the resolver to use to create the document.

@NonNull Uri parentDocumentUri

directory with FLAG_DIR_SUPPORTS_CREATE

@NonNull String mimeType

MIME type of new document

@NonNull String displayName

name of new document

Returns
@Nullable Uri

newly created document, or null if failed

getDocumentId

Added in 1.7.0
public static @Nullable String getDocumentId(@NonNull Uri documentUri)

Extract the COLUMN_DOCUMENT_ID from the given URI.

See also
getDocumentId

getTreeDocumentId

Added in 1.7.0
public static @Nullable String getTreeDocumentId(@NonNull Uri documentUri)

Extract the via COLUMN_DOCUMENT_ID from the given URI.

isDocumentUri

Added in 1.7.0
public static boolean isDocumentUri(@NonNull Context context, @Nullable Uri uri)

Checks if the given URI represents a Document backed by a DocumentsProvider.

See also
isDocumentUri

isTreeUri

Added in 1.7.0
public static boolean isTreeUri(@NonNull Uri uri)

Checks if the given URI represents a Document tree.

See also
isTreeUri

removeDocument

Added in 1.7.0
public static boolean removeDocument(
    @NonNull ContentResolver content,
    @NonNull Uri documentUri,
    @NonNull Uri parentDocumentUri
)

Removes the given document from a parent directory. In contrast to deleteDocument it requires specifying the parent. This method is especially useful if the document can be in multiple parents. This method was only added in N. On versions prior to this, this method calls through to deleteDocument.

Parameters
@NonNull ContentResolver content

the resolver to use to remove the document.

@NonNull Uri documentUri

document with FLAG_SUPPORTS_REMOVE

@NonNull Uri parentDocumentUri

parent document of the document to remove.

Returns
boolean

true if the document was removed successfully.

renameDocument

Added in 1.7.0
public static @Nullable Uri renameDocument(
    @NonNull ContentResolver content,
    @NonNull Uri documentUri,
    @NonNull String displayName
)

Change the display name of an existing document.

See also
renameDocument