# ActivityResultContracts.CreateDocument

Artifact: [androidx.activity:activity](https://developer.android.com/jetpack/androidx/releases/activity) [View Source](https://cs.android.com/search?q=file:androidx/activity/result/contract/ActivityResultContracts.kt+class:androidx.activity.result.contract.ActivityResultContracts.CreateDocument) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

*** ** * ** ***


```
open class ActivityResultContracts.CreateDocument : ActivityResultContract<String, Uri?>
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.activity.result.contract.ActivityResultContract](https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract)\<[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), [Uri](https://developer.android.com/reference/android/net/Uri.html)?\> ||
|   | ↳ | [androidx.activity.result.contract.ActivityResultContracts.CreateDocument](https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument) |

*** ** * ** ***

An `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract` to prompt the user to select a path for creating a new document of the given `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#mimeType()`, returning the `content:` `https://developer.android.com/reference/android/net/Uri.html` of the item that was created.

The input is the suggested name for the new file.

This can be extended to override `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#createIntent(android.content.Context,kotlin.String)` if you wish to pass additional extras to the Intent created by `super.createIntent()`.

## Summary

| ### Public constructors |
|---|
| `[CreateDocument](https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#CreateDocument())()` **This function is deprecated.** Using a wildcard mime type with CreateDocument is not recommended as it breaks the automatic handling of file extensions. |
| `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#CreateDocument(kotlin.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` |

| ### Public functions |
|---|---|
| `open https://developer.android.com/reference/android/content/Intent.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#createIntent(android.content.Context,kotlin.String)(context: https://developer.android.com/reference/android/content/Context.html, input: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Create an intent that can be used for `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)`. |
| `final https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract.SynchronousResult<https://developer.android.com/reference/android/net/Uri.html?>?` | `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#getSynchronousResult(android.content.Context,kotlin.String)(context: https://developer.android.com/reference/android/content/Context.html, input: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity. |
| `final https://developer.android.com/reference/android/net/Uri.html?` | `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#parseResult(kotlin.Int,android.content.Intent)(resultCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, intent: https://developer.android.com/reference/android/content/Intent.html?)` Convert result obtained from `https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)` to `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract`. |

## Public constructors

### CreateDocument

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0) Deprecated in [1.5.0](https://developer.android.com/jetpack/androidx/releases/activity#1.5.0)

```
[CreateDocument](https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.CreateDocument#CreateDocument())()
```

> [!CAUTION]
> **This function is deprecated.**   
> Using a wildcard mime type with CreateDocument is not recommended as it breaks the automatic handling of file extensions. Instead, specify the mime type by using the constructor that takes an concrete mime type (e.g.., CreateDocument("image/png")), use this instead:
>
> ```kotlin
> CreateDocument("todo/todo")
> ```

### CreateDocument

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

```
CreateDocument(mimeType: String)
```

## Public functions

### createIntent

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

```
@CallSuper
open fun createIntent(context: Context, input: String): Intent
```

Create an intent that can be used for `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)`.

### getSynchronousResult

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

```
final fun getSynchronousResult(context: Context, input: String): ActivityResultContract.SynchronousResult<Uri?>?
```

An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract.SynchronousResult<https://developer.android.com/reference/android/net/Uri.html?>?` | the result wrapped in a `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract.SynchronousResult` or `null` if the call should proceed to start an activity. |

### parseResult

```
final fun parseResult(resultCode: Int, intent: Intent?): Uri?
```

Convert result obtained from `https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)` to `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract`.