Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.media.projection.MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) |

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#Builder()()` <br /> |

| Public methods ||
|---|---|
| [MediaProjectionConfig](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#build()()` Builds a new immutable instance of `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig` |
| [MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setAudioRequested(kotlin.Boolean)(isAudioRequested: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` This method informs the screen capture UI that the user should be presented with an option to also record audio along with the screen content. |
| [MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setInitiallySelectedSource(kotlin.Int)(projectionSource: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Indicates which projection source the UI component should display to the user first. |
| [MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setOwnAppContentProvided(kotlin.Boolean)(isEnabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Indicates to the system that the requesting application is offering its own `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionAppContent` to be shared as `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP_CONTENT:kotlin.Int`. |
| [MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setRequesterHint(kotlin.String)(requesterHint: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?)` Let the requesting app indicate who the requester of this `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjection` session is. |
| [MediaProjectionConfig.Builder](https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setSourceEnabled(kotlin.Int,%20kotlin.Boolean)(source: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Set whether the UI component requesting the user permission to share their screen should display an option to share the specified source |

## Public constructors

### Builder

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder()
```

## Public methods

### build

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): MediaProjectionConfig
```

Builds a new immutable instance of `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig`

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig` | This value cannot be `null`. |

### setAudioRequested

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setAudioRequested(isAudioRequested: Boolean): MediaProjectionConfig.Builder
```

This method informs the screen capture UI that the user should be presented with an option to also record audio along with the screen content. When `isAudioRequested` is set to true, the consent dialog will display a control, such as a toggle, allowing the user to enable or disable audio capture for the projection session. If set to false, this control will not be shown.

| Parameters ||
|---|---|
| `isAudioRequested` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): true to request that the UI shows an audio capture option, false otherwise. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` | this Builder instance for chaining. This value cannot be `null`. |

### setInitiallySelectedSource

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setInitiallySelectedSource(projectionSource: Int): MediaProjectionConfig.Builder
```

Indicates which projection source the UI component should display to the user first. Calling this method without enabling the respective choice will have no effect.

| Parameters ||
|---|---|
| `projectionSource` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Value is either `0` or a combination of the following: - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_DISPLAY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP_CONTENT:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` | instance of this `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#`. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setSourceEnabled(kotlin.Int,%20kotlin.Boolean)`

### setOwnAppContentProvided

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setOwnAppContentProvided(isEnabled: Boolean): MediaProjectionConfig.Builder
```

Indicates to the system that the requesting application is offering its own `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionAppContent` to be shared as `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP_CONTENT:kotlin.Int`.

When `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#setOwnAppContentProvided(kotlin.Boolean)` is set to `true`, the requesting app's content will override any content from other apps that might have been displayed by the system.

If this application wishes to offer its own content to be shared, it must declare, in its manifest, a `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` inheriting from `https://developer.android.com/reference/kotlin/android/media/projection/AppContentProjectionService` and declare an intent filter with an {@value AppContentProjectionService#SERVICE_INTERFACE} action. The service must be exported and protected by the android.Manifest.permission#MANAGE_MEDIA_PROJECTION permission

<br />

```kotlin
</application>
    ...
     <service
          android:exported="true"
          android:name="com.example.AppContentSharingService"
          android:permission="android.permission.MANAGE_MEDIA_PROJECTION">
        <intent-filter>
          <action android:name="android.media.projection.AppContentProjectionService"/>
        </intent-filter>
      </service>
    </application>
  
```

If supported by the device, the content will be displayed to the user in the media projection picker and `https://developer.android.com/reference/kotlin/android/media/projection/AppContentProjectionService#onContentRequest(android.media.projection.AppContentRequest)` will be called, offering the a chance to this application to provide or update the content to be shared.

If the user selects an item from this list, `https://developer.android.com/reference/kotlin/android/media/projection/AppContentProjectionService#onLoopbackProjectionStarted(android.media.projection.AppContentProjectionSession,%20kotlin.Int)` will be called and the projection session will be considered as started.

If the shared content becomes unavailable, this application will be responsible for calling `https://developer.android.com/reference/kotlin/android/media/projection/AppContentProjectionSession#notifySessionStop()`. If the session is stopped outside of this application `https://developer.android.com/reference/kotlin/android/media/projection/AppContentProjectionService#onSessionStopped(android.media.projection.AppContentProjectionSession)` will be called.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` | This value cannot be `null`. |

### setRequesterHint

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setRequesterHint(requesterHint: String?): MediaProjectionConfig.Builder
```

Let the requesting app indicate who the requester of this `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjection` session is.

The UI component prompting the user for the permission to start the session can use this hint to provide more information about the origin of the request (e.g. a browser tab title, a meeting id if sharing to a video conferencing app, a player name if sharing the screen within a game).

Note that setting this won't hide or change the name of the application requesting the session.

| Parameters ||
|---|---|
| `requesterHint` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?: the text representing the requester of this session. This value may be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` | instance of this `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#`. This value cannot be `null`. |

### setSourceEnabled

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setSourceEnabled(
    source: Int, 
    enabled: Boolean
): MediaProjectionConfig.Builder
```

Set whether the UI component requesting the user permission to share their screen should display an option to share the specified source

| Parameters ||
|---|---|
| `source` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the projection source to enable or disable. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_DISPLAY:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig#PROJECTION_SOURCE_APP_CONTENT:kotlin.Int` |
| `enabled` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): true to enable the source, false otherwise |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/projection/MediaProjectionConfig.Builder#` | this instance for chaining. This value cannot be `null`. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if the source is not one of the valid sources. |