# Alert.Builder

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/Alert.java+class:androidx.car.app.model.Alert.Builder) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.2.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/car/app/model/Alert.Builder "View this page in Java")


```
class Alert.Builder
```

<br />

*** ** * ** ***

A builder of `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#Builder(int,androidx.car.app.model.CarText,long)(alertId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, title: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText, durationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Creates an `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` instance. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#addAction(androidx.car.app.model.Action)(action: https://developer.android.com/reference/kotlin/androidx/car/app/model/Action)` Adds the `action` to the list of actions on the alert. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#build()()` Constructs the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert` defined by this builder. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#setCallback(androidx.car.app.model.AlertCallback)(callback: https://developer.android.com/reference/kotlin/androidx/car/app/model/AlertCallback)` Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/AlertCallback` to receive alert related events. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#setIcon(androidx.car.app.model.CarIcon)(icon: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)` Sets the icon to display in the alert. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder#setSubtitle(androidx.car.app.model.CarText)(subtitle: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText)` Sets the subtitle to display in the alert, with support for multiple length variants. |

## Public constructors

### Builder

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

```
Builder(alertId: Int, title: CarText, durationMillis: Long)
```

Creates an `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert.Builder` instance.

Text spans are supported.

| Parameters |
|---|---|
| `alertId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The unique identifier used for the alert. Alerts with the same id are considered equal. |
| `title: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` | The title of the alert. |
| `durationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The maximum duration the alert can be shown in milli seconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `duration` is not positive |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |

## Public functions

### addAction

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

```
fun addAction(action: Action): Alert.Builder
```

Adds the `action` to the list of actions on the alert.

An alert can have up to 2 actions.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if more than 2 actions are added. |

### build

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

```
fun build(): Alert
```

Constructs the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert` defined by this builder.

### setCallback

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

```
fun setCallback(callback: AlertCallback): Alert.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/AlertCallback` to receive alert related events.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `callback` is `null` |

### setIcon

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

```
fun setIcon(icon: CarIcon): Alert.Builder
```

Sets the icon to display in the alert.

#### Icon Sizing Guidance

To minimize scaling artifacts across a wide range of car screens, apps should provide icons targeting a 88 x 88 dp bounding box. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` for more details related to providing icon and image resources that work with different car screen pixel densities.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `icon` is `null` |

### setSubtitle

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

```
fun setSubtitle(subtitle: CarText): Alert.Builder
```

Sets the subtitle to display in the alert, with support for multiple length variants.

Text spans are supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `subtitle` is `null` |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |