Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public static final class PushNotification.Builder

  1. Object
  2. PushNotification.Builder
Builds a PushNotification. A builder can be reused: build() takes a snapshot.

Methods

public PushNotification.Builder id(String value)
public PushNotification.Builder title(String value)
public PushNotification.Builder body(String value)
public PushNotification.Builder imageUrl(String value)
public PushNotification.Builder deepLink(String value)
public PushNotification.Builder collapseKey(String value)
public PushNotification.Builder ttlSeconds(int value)How long the providers keep trying to deliver the message.
public PushNotification.Builder silent(boolean value)
public PushNotification.Builder data(String key, Object value)Adds a value the app reads from the message’s data, or removes it.
public PushNotification.Builder platform(String providerId, Map<String, ?> options)Adds options for one provider, which the other providers ignore.
public PushNotification.Builder surface(Map<String, ?> command)Sets a widget or Live Activity command, which the app applies before its listener sees the message.
public PushNotification build()

Inherited methods

Method details

id

public PushNotification.Builder id(String value)

Parameters

value String
an id for the message, or null to clear it

Returns

this builder

title

public PushNotification.Builder title(String value)

Parameters

value String
the visible title, or null to clear it

Returns

this builder

body

public PushNotification.Builder body(String value)

Parameters

value String
the visible body, or null to clear it

Returns

this builder

imageUrl

public PushNotification.Builder imageUrl(String value)

Parameters

value String
an HTTPS URL of an image to show, or null to clear it

Returns

this builder

deepLink

public PushNotification.Builder deepLink(String value)

Parameters

value String
the deep link the app opens when the user taps the notification, or null to clear it

Returns

this builder

collapseKey

public PushNotification.Builder collapseKey(String value)

Parameters

value String
a key under which a newer message replaces an older undelivered one, or null to clear it

Returns

this builder

ttlSeconds

public PushNotification.Builder ttlSeconds(int value)
How long the providers keep trying to deliver the message.

Parameters

value int
the lifetime in seconds, greater than zero

Returns

this builder

Throws

IllegalArgumentException
if the value isn’t positive

silent

public PushNotification.Builder silent(boolean value)

Parameters

value boolean
true for a data-only message that shows nothing

Returns

this builder

data

public PushNotification.Builder data(String key, Object value)
Adds a value the app reads from the message’s data, or removes it.

Parameters

key String
the name
value Object
a JSON value (string, number, boolean, map or list), or null to remove the key

Returns

this builder

Throws

IllegalArgumentException
if the key is empty or has surrounding whitespace

platform

public PushNotification.Builder platform(String providerId, Map<String, ?> options)
Adds options for one provider, which the other providers ignore.

Parameters

providerId String
fcm, apns, huawei, wns or web, or one of the aliases PushTarget.of(String, String) accepts
options Map<String, ?>
the provider’s options, or null to remove them

Returns

this builder

Throws

IllegalArgumentException
if the provider is unknown

surface

public PushNotification.Builder surface(Map<String, ?> command)
Sets a widget or Live Activity command, which the app applies before its listener sees the message. PushNotification.liveUpdate, PushNotification.liveEnd and PushNotification.widget build one.

Parameters

command Map<String, ?>
the command, or null to remove it

Returns

this builder

Throws

IllegalArgumentException
if the command’s operation isn’t widget, live-update or live-end

build

public PushNotification build()

Returns

an immutable snapshot of the message built so far