# DocumentsContractCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/provider/DocumentsContractCompat.java+class:androidx.core.provider.DocumentsContractCompat) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

*** ** * ** ***


```
public final class DocumentsContractCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/provider/DocumentsContract.html`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat.DocumentCompat` Helper for accessing features in `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html`. |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#buildChildDocumentsUri(java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html parentDocumentId )` Build URI representing the children of the target directory in a document provider. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#buildChildDocumentsUriUsingTree(android.net.Uri,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html treeUri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html parentDocumentId )` Build URI representing the children of the target directory in a document provider. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#buildDocumentUri(java.lang.String,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html documentId)` Build URI representing the target `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` in a document provider. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#buildDocumentUriUsingTree(android.net.Uri,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html treeUri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html documentId)` Build URI representing the target `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` in a document provider. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#buildTreeDocumentUri(java.lang.String,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html documentId)` Build URI representing access to descendant documents of the given `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#createDocument(android.content.ContentResolver,android.net.Uri,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html content, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html parentDocumentUri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html mimeType, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html displayName )` Create a new document with given MIME type and display name. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#getDocumentId(android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html documentUri)` Extract the `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` from the given URI. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#getTreeDocumentId(android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html documentUri)` Extract the via `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` from the given URI. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#isDocumentUri(android.content.Context,android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html uri)` Checks if the given URI represents a `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html` backed by a `https://developer.android.com/reference/android/provider/DocumentsProvider.html`. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#isTreeUri(android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri)` Checks if the given URI represents a `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html` tree. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#removeDocument(android.content.ContentResolver,android.net.Uri,android.net.Uri)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html content, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html documentUri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html parentDocumentUri )` Removes the given document from a parent directory. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat#renameDocument(android.content.ContentResolver,android.net.Uri,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html content, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html documentUri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html displayName )` Change the display name of an existing document. |

## Public methods

### buildChildDocumentsUri

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#buildChildDocumentsUri(java.lang.String, java.lang.String)` |   |

### buildChildDocumentsUriUsingTree

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#buildChildDocumentsUriUsingTree(android.net.Uri, java.lang.String)` |   |

### buildDocumentUri

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

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

Build URI representing the target `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` in a document provider. When queried, a provider will return a single row with columns defined by `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#buildDocumentUri(java.lang.String, java.lang.String)` |   |

### buildDocumentUriUsingTree

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public static @Nullable Uri buildDocumentUriUsingTree(@NonNull Uri treeUri, @NonNull String documentId)
```

Build URI representing the target `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` in a document provider. When queried, a provider will return a single row with columns defined by `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html`.

### buildTreeDocumentUri

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

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

Build URI representing access to descendant documents of the given `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#buildTreeDocumentUri(java.lang.String, java.lang.String)` |   |

### createDocument

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html content` | the resolver to use to create the document. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html parentDocumentUri` | directory with `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_DIR_SUPPORTS_CREATE` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html mimeType` | MIME type of new document |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html displayName` | name of new document |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Uri.html` | newly created document, or `null` if failed |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` |   |

### getDocumentId

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public static @Nullable String getDocumentId(@NonNull Uri documentUri)
```

Extract the `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` from the given URI.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#getDocumentId(android.net.Uri)` |   |

### getTreeDocumentId

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public static @Nullable String getTreeDocumentId(@NonNull Uri documentUri)
```

Extract the via `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID` from the given URI.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#getTreeDocumentId(android.net.Uri)` |   |

### isDocumentUri

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public static boolean isDocumentUri(@NonNull Context context, @Nullable Uri uri)
```

Checks if the given URI represents a `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html` backed by a `https://developer.android.com/reference/android/provider/DocumentsProvider.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#isDocumentUri(android.content.Context, android.net.Uri)` |   |

### isTreeUri

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public static boolean isTreeUri(@NonNull Uri uri)
```

Checks if the given URI represents a `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html` tree.

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#isTreeUri(android.net.Uri)` |   |

### removeDocument

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 `https://developer.android.com/reference/android/provider/DocumentsContract.html#deleteDocument(android.content.ContentResolver, android.net.Uri)` it requires specifying the parent. This method is especially useful if the document can be in multiple parents. This method was only added in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#N`. On versions prior to this, this method calls through to `https://developer.android.com/reference/android/provider/DocumentsContract.html#deleteDocument(android.content.ContentResolver, android.net.Uri)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentResolver.html content` | the resolver to use to remove the document. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html documentUri` | document with `https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_SUPPORTS_REMOVE` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html parentDocumentUri` | parent document of the document to remove. |

| Returns |
|---|---|
| `boolean` | true if the document was removed successfully. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` |   |

### renameDocument

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` |   |

| See also |
|---|---|
| `https://developer.android.com/reference/android/provider/DocumentsContract.html#renameDocument(android.content.ContentResolver, android.net.Uri, java.lang.String)` |   |