Android 12 Developer Preview is here! Try it out, and give us your feedback!

MessageTemplate.Builder

public static final class MessageTemplate.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.MessageTemplate.Builder


A builder of MessageTemplate.

Summary

Public constructors

Builder(CharSequence message)

Returns a MessageTemplate.Builder instance.

Builder(CarText message)

Returns a MessageTemplate.Builder instance.

Public methods

MessageTemplate.Builder addAction(Action action)

Adds an Action to display along with the message.

MessageTemplate build()

Constructs the MessageTemplate defined by this builder.

MessageTemplate.Builder setDebugMessage(String debugMessage)

Sets a debug message for debugging purposes.

MessageTemplate.Builder setDebugMessage(Throwable cause)

Sets a Throwable for debugging purposes.

MessageTemplate.Builder setHeaderAction(Action headerAction)

Sets the Action that will be displayed in the header of the template.

MessageTemplate.Builder setIcon(CarIcon icon)

Sets the icon to be displayed along with the message.

MessageTemplate.Builder setTitle(CharSequence title)

Sets the title of the template.

Inherited methods

Public constructors

Builder

public Builder (CharSequence message)

Returns a MessageTemplate.Builder instance.

Parameters
message CharSequence: the text message to display in the template

Throws
NullPointerException if the message is null

Builder

public Builder (CarText message)

Returns a MessageTemplate.Builder instance.

Parameters
message CarText: the text message to display in the template

Throws
NullPointerException if the message is null

Public methods

addAction

public MessageTemplate.Builder addAction (Action action)

Adds an Action to display along with the message.

Any actions above the maximum limit of 2 will be ignored.

Parameters
action Action

Returns
MessageTemplate.Builder

Throws
NullPointerException if action is null

build

public MessageTemplate build ()

Constructs the MessageTemplate defined by this builder.

Requirements

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

Either a header Action or title must be set on the template.

Returns
MessageTemplate

Throws
IllegalStateException if the message is empty, or if the template does not have either a title or header Action set

setDebugMessage

public MessageTemplate.Builder setDebugMessage (String debugMessage)

Sets a debug message for debugging purposes.

The debug message will be displayed along with the cause set in setDebugMessage(String).

The host may choose to not display this debugging information if it doesn't deem it appropriate, for example, when running on a production environment rather than in a simulator such as the Desktop Head Unit.

Parameters
debugMessage String

Returns
MessageTemplate.Builder

Throws
NullPointerException if icon is null

setDebugMessage

public MessageTemplate.Builder setDebugMessage (Throwable cause)

Sets a Throwable for debugging purposes.

The cause will be displayed along with the message set in setDebugMessage(String).

The host may choose to not display this debugging information if it doesn't deem it appropriate, for example, when running on a production environment rather than in a simulator such as the Desktop Head Unit.

Parameters
cause Throwable

Returns
MessageTemplate.Builder

Throws
NullPointerException if icon is null

setHeaderAction

public MessageTemplate.Builder setHeaderAction (Action headerAction)

Sets the 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 Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
MessageTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements
NullPointerException if headerAction is null

setIcon

public MessageTemplate.Builder setIcon (CarIcon icon)

Sets the icon to be displayed along with the message.

Unless set with this method, an icon will not be displayed.

Icon Sizing Guidance

The provided icon should have a maximum size of 64 x 64 dp. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down and centered inside the bounding box while preserving the aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
icon CarIcon

Returns
MessageTemplate.Builder

Throws
NullPointerException if icon is null

setTitle

public MessageTemplate.Builder setTitle (CharSequence title)

Sets the title of the template.

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

Spans are not supported in the input string.

Parameters
title CharSequence

Returns
MessageTemplate.Builder

Throws
NullPointerException if title is null

See also: