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

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/content/ContextParams.Builder "View this page in Java")

```
class Builder
```

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

Builder for creating a `https://developer.android.com/reference/kotlin/android/content/ContextParams`.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#Builder()()` Create a new builder. |
| `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#Builder(android.content.ContextParams)(params: https://developer.android.com/reference/kotlin/android/content/ContextParams)` Create a new builder that inherits all sub-parameters by default. |

| Public methods ||
|---|---|
| [ContextParams](https://developer.android.com/reference/kotlin/android/content/ContextParams) | `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#build()()` Creates a new instance. |
| [ContextParams.Builder](https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#) | `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#setAttributionTag(kotlin.String)(attributionTag: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?)` Sets an attribution tag against which to track permission accesses. |
| [ContextParams.Builder](https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#) | `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#setNextAttributionSource(android.content.AttributionSource)(next: https://developer.android.com/reference/kotlin/android/content/AttributionSource?)` Sets the attribution source for the app on whose behalf you are doing the work. |
| [ContextParams.Builder](https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#) | `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#setShouldRegisterAttributionSource(kotlin.Boolean)(shouldRegister: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Sets whether the attribution source associated with the context created from these params should be registered. |

## Public constructors

### Builder

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

```
Builder()
```

Create a new builder.

This is valuable when you are interested in having explicit control over every sub-parameter, and don't want to inherit any values from an existing Context.

Developers should strongly consider using `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#Builder(android.content.ContextParams)` instead of this constructor, since that will will automatically inherit any new sub-parameters added in future platform releases.

### Builder

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

```
Builder(params: ContextParams)
```

Create a new builder that inherits all sub-parameters by default.

This is valuable when you are only interested in overriding specific sub-parameters, and want to preserve all other parameters. Setting a specific sub-parameter on the returned builder will override any inherited value.

| Parameters ||
|---|---|
| `params` | [ContextParams](https://developer.android.com/reference/kotlin/android/content/ContextParams): This value cannot be `null`. |

## Public methods

### build

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

```
fun build(): ContextParams
```

Creates a new instance.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/content/ContextParams` | The new instance. This value cannot be `null`. |

### setAttributionTag

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

```
fun setAttributionTag(attributionTag: String?): ContextParams.Builder
```

Sets an attribution tag against which to track permission accesses.

| Parameters ||
|---|---|
| `attributionTag` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?: The attribution tag. This value may be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#` | This builder. This value cannot be `null`. |

### setNextAttributionSource

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

```
fun setNextAttributionSource(next: AttributionSource?): ContextParams.Builder
```

Sets the attribution source for the app on whose behalf you are doing the work.

| Parameters ||
|---|---|
| `next` | [AttributionSource](https://developer.android.com/reference/kotlin/android/content/AttributionSource)?: The permission identity of the receiving app. This value may be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder#` | This builder. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/content/AttributionSource`

### setShouldRegisterAttributionSource

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

```
fun setShouldRegisterAttributionSource(shouldRegister: Boolean): ContextParams.Builder
```

Sets whether the attribution source associated with the context created from these params should be registered.

| Parameters ||
|---|---|
| `shouldRegister` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): Whether the attribution source associated with the Context being created should be registered. |

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