# DocumentsContractCompat

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/provider/DocumentsContractCompat "View this page in Java")

<br />

```
class DocumentsContractCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[DocumentsContract](https://developer.android.com/reference/android/provider/DocumentsContract.html).

## Summary

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

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

## Public functions

### buildChildDocumentsUri

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

```
java-static fun buildChildDocumentsUri(authority: String, parentDocumentId: String?): Uri?
```

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](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html).  

|                                                                               See also                                                                               |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [buildChildDocumentsUri](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)  

```
java-static fun buildChildDocumentsUriUsingTree(treeUri: Uri, parentDocumentId: String): Uri?
```

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](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html).  

|                                                                                       See also                                                                                        |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [buildChildDocumentsUriUsingTree](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)  

```
java-static fun buildDocumentUri(authority: String, documentId: String): Uri?
```

Build URI representing the target[COLUMN_DOCUMENT_ID](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[Document](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html).  

|                                                                         See also                                                                         |
|----------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [buildDocumentUri](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)  

```
java-static fun buildDocumentUriUsingTree(treeUri: Uri, documentId: String): Uri?
```

Build URI representing the target[COLUMN_DOCUMENT_ID](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[Document](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)  

```
java-static fun buildTreeDocumentUri(authority: String, documentId: String): Uri?
```

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

|                                                                             See also                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [buildTreeDocumentUri](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)  

```
java-static fun createDocument(
    content: ContentResolver,
    parentDocumentUri: Uri,
    mimeType: String,
    displayName: String
): Uri?
```

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

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `content: `[ContentResolver](https://developer.android.com/reference/android/content/ContentResolver.html) | the resolver to use to create the document.                                                                                                                   |
| `parentDocumentUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)                   | directory with[FLAG_DIR_SUPPORTS_CREATE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_DIR_SUPPORTS_CREATE()) |
| `mimeType: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)              | MIME type of new document                                                                                                                                     |
| `displayName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)           | name of new document                                                                                                                                          |

|                                Returns                                 |
|------------------------------------------------------------------------|-------------------------------------------|
| [Uri](https://developer.android.com/reference/android/net/Uri.html)`?` | newly created document, or`null`if failed |

|                                                   Throws                                                    |
|-------------------------------------------------------------------------------------------------------------|---|
| [java.io.FileNotFoundException](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)  

```
java-static fun getDocumentId(documentUri: Uri): String?
```

Extract the[COLUMN_DOCUMENT_ID](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#COLUMN_DOCUMENT_ID())from the given URI.  

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [getDocumentId](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)  

```
java-static fun getTreeDocumentId(documentUri: Uri): String?
```

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

|                                                                See also                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------|---|
| [getTreeDocumentId](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)  

```
java-static fun isDocumentUri(context: Context, uri: Uri?): Boolean
```

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

|                                                                         See also                                                                         |
|----------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [isDocumentUri](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)  

```
java-static fun isTreeUri(uri: Uri): Boolean
```

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

|                                                        See also                                                         |
|-------------------------------------------------------------------------------------------------------------------------|---|
| [isTreeUri](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)  

```
java-static fun removeDocument(
    content: ContentResolver,
    documentUri: Uri,
    parentDocumentUri: Uri
): Boolean
```

Removes the given document from a parent directory. In contrast to[deleteDocument](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[N](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#N()). On versions prior to this, this method calls through to[deleteDocument](https://developer.android.com/reference/android/provider/DocumentsContract.html#deleteDocument(android.content.ContentResolver, android.net.Uri)).  

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `content: `[ContentResolver](https://developer.android.com/reference/android/content/ContentResolver.html) | the resolver to use to remove the document.                                                                                                          |
| `documentUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)                         | document with[FLAG_SUPPORTS_REMOVE](https://developer.android.com/reference/android/provider/DocumentsContract.Document.html#FLAG_SUPPORTS_REMOVE()) |
| `parentDocumentUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)                   | parent document of the document to remove.                                                                                                           |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if the document was removed successfully. |

|                                                   Throws                                                    |
|-------------------------------------------------------------------------------------------------------------|---|
| [java.io.FileNotFoundException](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)  

```
java-static fun renameDocument(
    content: ContentResolver,
    documentUri: Uri,
    displayName: String
): Uri?
```

Change the display name of an existing document.  

|                                                   Throws                                                    |
|-------------------------------------------------------------------------------------------------------------|---|
| [java.io.FileNotFoundException](https://developer.android.com/reference/java/io/FileNotFoundException.html) |   |

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