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

public final class PushNotification

  1. Object
  2. PushNotification

A push message in the schema-3 envelope the Codename One push service delivers and the app’s PushClient receives.

PushNotification message = PushNotification.builder()
        .title("Your driver is here")
        .body("Look for the blue car")
        .deepLink("app://trip/42")
        .data("tripId", "42")
        .build();

A message carries at least a body, data, or a surface command; CloudPush refuses one that has none of them, because the service would.

This is the server’s counterpart of the app’s com.codename1.push.PushMessage and writes the same fields. It isn’t that class shared with the backend: PushMessage parses and writes through com.codename1.io.JSONParser, which reaches com.codename1.processing.Result and through it the XML DOM, none of which the server compiles. The two agree on the wire, which is the contract that matters; the envelope is JSON.

A built notification is immutable: toMap() answers a copy.

Nested types

class PushNotification.BuilderBuilds a PushNotification.

Fields

public static final int SCHEMA_VERSION = 3The envelope schema this class writes.

Methods

public static PushNotification.Builder builder()
public String toJson()The envelope as JSON.
public Map<String, Object> toMap()The envelope as maps and lists, in the order the fields were set.
public static Map<String, Object> liveUpdate(String activityId, Map<String, ?> state)A surface command that updates a running Live Activity.
public static Map<String, Object> liveEnd(String activityId, Map<String, ?> finalState, boolean dismissImmediately)A surface command that ends a Live Activity.
public static Map<String, Object> widget(String kind, String timelineJson)A surface command that publishes new widget content.

Inherited methods

Field details

SCHEMA_VERSION

public static final int SCHEMA_VERSION = 3
The envelope schema this class writes.

Method details

builder

public static PushNotification.Builder builder()

Returns

a builder with the schema already set

toJson

public String toJson()
The envelope as JSON.

Returns

the JSON object the service receives as message

toMap

public Map<String, Object> toMap()
The envelope as maps and lists, in the order the fields were set.

Returns

a copy; changing it doesn’t change this notification

liveUpdate

public static Map<String, Object> liveUpdate(String activityId, Map<String, ?> state)

A surface command that updates a running Live Activity.

The app applies it with LiveActivity.updateRemote, before any listener sees the message, so a lock-screen activity moves on even when the app isn’t running.

Parameters

activityId String
the id the app started the activity under
state Map<String, ?>
the activity’s new state, a flat map of names to JSON values; sent as a JSON string with its keys sorted, the way the app serializes state itself

Returns

a command for Builder.surface(Map)

Throws

IllegalArgumentException
if the id is empty or a state key is null

liveEnd

public static Map<String, Object> liveEnd(String activityId, Map<String, ?> finalState, boolean dismissImmediately)
A surface command that ends a Live Activity.

Parameters

activityId String
the id the app started the activity under
finalState Map<String, ?>
the state to show as the activity ends, or null to leave the last one
dismissImmediately boolean
true to remove the activity now rather than letting the system keep the final state on screen for a while

Returns

a command for Builder.surface(Map)

Throws

IllegalArgumentException
if the id is empty or a state key is null

widget

public static Map<String, Object> widget(String kind, String timelineJson)
A surface command that publishes new widget content.

Parameters

kind String
the widget kind the app declared
timelineJson String
the timeline, already serialized as JSON

Returns

a command for Builder.surface(Map)

Throws

IllegalArgumentException
if either argument is empty