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
- Object
- PushNotification.Builder
Builds a
PushNotification. A builder can be reused: build() takes a
snapshot.Methods
Inherited methods
Method details
id
public PushNotification.Builder id(String value)Parameters
valueString- an id for the message, or null to clear it
Returns
this builder
title
public PushNotification.Builder title(String value)Parameters
valueString- the visible title, or null to clear it
Returns
this builder
body
public PushNotification.Builder body(String value)Parameters
valueString- the visible body, or null to clear it
Returns
this builder
imageUrl
public PushNotification.Builder imageUrl(String value)Parameters
valueString- an HTTPS URL of an image to show, or null to clear it
Returns
this builder
deepLink
public PushNotification.Builder deepLink(String value)Parameters
valueString- 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
valueString- 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
valueint- 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
valueboolean- 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
keyString- the name
valueObject- 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
providerIdStringfcm,apns,huawei,wnsorweb, or one of the aliasesPushTarget.of(String, String)acceptsoptionsMap<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
commandMap<String, ?>- the command, or null to remove it
Returns
this builder
Throws
IllegalArgumentException- if the command’s
operationisn’twidget,live-updateorlive-end
build
public PushNotification build()Returns
an immutable snapshot of the message built so far