# LongMessageTemplate.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/LongMessageTemplate.java+class:androidx.car.app.model.LongMessageTemplate.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***

<br />

```
@RequiresCarApi(value = 2)
public final class LongMessageTemplate.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#Builder(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html message)` Returns a `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` instance. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` | `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#addAction(androidx.car.app.model.Action)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action action)` Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` to display along with the message. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate` | `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` | `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#setActionStrip(androidx.car.app.model.ActionStrip)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/ActionStrip actionStrip)` Sets the `https://developer.android.com/reference/androidx/car/app/model/ActionStrip` for this template or `null` to not display an `https://developer.android.com/reference/androidx/car/app/model/ActionStrip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` | `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#setHeaderAction(androidx.car.app.model.Action)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action headerAction)` Sets the `https://developer.android.com/reference/androidx/car/app/model/Action` that will be displayed in the header of the template. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` | `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder#setTitle(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html title)` Sets the title of the template. |

## Public constructors

### Builder

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

```
public Builder(@NonNull CharSequence message)
```

Returns a `https://developer.android.com/reference/androidx/car/app/model/LongMessageTemplate.Builder` instance.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html message` | the text message to display in the template. This message will only be displayed when the car is parked. |

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

## Public methods

### addAction

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

```
public @NonNull LongMessageTemplate.Builder addAction(@NonNull Action action)
```

Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` to display along with the message.

#### Requirements

This template allows up to 2 `https://developer.android.com/reference/androidx/car/app/model/Action`s in its body, and they must use a `https://developer.android.com/reference/androidx/car/app/model/ParkedOnlyOnClickListener`. One of these actions can be declared as primary via `https://developer.android.com/reference/androidx/car/app/model/Action.Builder#setFlags(int)`. Each action's title color can be customized with `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan` instances. Any other span is not supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `action` does not meet the requirements |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `action` is `null` |

### build

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

```
public @NonNull LongMessageTemplate build()
```

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

#### Requirements

A non-empty message must be set on the template.

If none of the header `https://developer.android.com/reference/androidx/car/app/model/Action`, the header title or the action strip have been set on the template, the header is hidden.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the message is empty |

### setActionStrip

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

```
public @NonNull LongMessageTemplate.Builder setActionStrip(@NonNull ActionStrip actionStrip)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/ActionStrip` for this template or `null` to not display an `https://developer.android.com/reference/androidx/car/app/model/ActionStrip`.

Unless set with this method, the template will not have an action strip.

#### Requirements

This template allows up to 2 `https://developer.android.com/reference/androidx/car/app/model/Action`s in its `https://developer.android.com/reference/androidx/car/app/model/ActionStrip`. Of the 2 allowed `https://developer.android.com/reference/androidx/car/app/model/Action`s, one of them can contain a title as set via `https://developer.android.com/reference/androidx/car/app/model/Action.Builder#setTitle(java.lang.CharSequence)`. Otherwise, only `https://developer.android.com/reference/androidx/car/app/model/Action`s with icons are allowed.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `actionStrip` does not meet the requirements |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `actionStrip` is `null` |

### setHeaderAction

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

```
public @NonNull LongMessageTemplate.Builder setHeaderAction(@NonNull Action headerAction)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/Action` that will be displayed in the header of the template.

Unless set with this method, the template will not have a header action.

#### Requirements

This template only supports either one of `https://developer.android.com/reference/androidx/car/app/model/Action#APP_ICON()` and `https://developer.android.com/reference/androidx/car/app/model/Action#BACK()` as a header `https://developer.android.com/reference/androidx/car/app/model/Action`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `headerAction` does not meet the template's requirements |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `headerAction` is `null` |

### setTitle

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

```
public @NonNull LongMessageTemplate.Builder setTitle(@NonNull CharSequence title)
```

Sets the title of the template.

Unless set with this method, the template will not have a title.

Only `https://developer.android.com/reference/androidx/car/app/model/DistanceSpan`s and `https://developer.android.com/reference/androidx/car/app/model/DurationSpan`s are supported in the input string.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `title` contains unsupported spans |

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