RemoteMessage.Builder

public class RemoteMessage.Builder


Builder object for constructing RemoteMessage instances.

Summary

Public fields

final Map<StringString>

Public constructors

Sets the destination of the message.

Public methods

@NonNull RemoteMessage.Builder

Adds a data key value pair to the message.

@NonNull RemoteMessage

Build a RemoteMessage instance.

@NonNull RemoteMessage.Builder

Clears the message data.

@NonNull RemoteMessage.Builder

Sets the collapse key of the message.

@NonNull RemoteMessage.Builder

Sets the message data to the contents of data.

@NonNull RemoteMessage.Builder

Sets the messages ID.

@NonNull RemoteMessage.Builder

Sets the type of message.

@NonNull RemoteMessage.Builder
setTtl(@IntRange(from = 0, to = 86400) int ttl)

Sets the message time to live in seconds.

Public fields

data

public final Map<StringStringdata

Public constructors

Builder

public Builder(@NonNull String to)

Sets the destination of the message.

Parameters
@NonNull String to

The destination of the message in the format of SENDER_ID@fcm.googleapis.com. The SENDER_ID should be the FirebaseApp gcm sender id.

Public methods

addData

public @NonNull RemoteMessage.Builder addData(@NonNull String key, @Nullable String value)

Adds a data key value pair to the message.

An existing value with the same key will be replaced by the new value.

build

public @NonNull RemoteMessage build()

Build a RemoteMessage instance.

clearData

public @NonNull RemoteMessage.Builder clearData()

Clears the message data.

setCollapseKey

public @NonNull RemoteMessage.Builder setCollapseKey(@Nullable String collapseKey)

Sets the collapse key of the message.

A pending message will be replaced by a new message with the same collapse key if it is currently unable to be delivered to the recipient.

setData

public @NonNull RemoteMessage.Builder setData(@NonNull Map<StringString> data)

Sets the message data to the contents of data.

Any existing data will be removed.

setMessageId

public @NonNull RemoteMessage.Builder setMessageId(@NonNull String messageId)

Sets the messages ID.

Parameters
@NonNull String messageId

ID of the message. This is generated by the application. It must be unique for each message. This allows error callbacks and debugging.

setMessageType

public @NonNull RemoteMessage.Builder setMessageType(@Nullable String messageType)

Sets the type of message.

setTtl

public @NonNull RemoteMessage.Builder setTtl(@IntRange(from = 0, to = 86400) int ttl)

Sets the message time to live in seconds.

If 0, the message send will be attempted immediately and will be dropped if the device is not connected. Otherwise, the message will be queued.