Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class PushNotification
- Object
- 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.Builder | Builds a PushNotification. |
Fields
public static final int SCHEMA_VERSION = 3 | The envelope schema this class writes. |
Methods
Inherited methods
Field details
SCHEMA_VERSION
public static final int SCHEMA_VERSION = 3Method details
builder
public static PushNotification.Builder builder()Returns
toJson
public String toJson()Returns
messagetoMap
public Map<String, Object> toMap()Returns
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
activityIdString- the id the app started the activity under
stateMap<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
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)Parameters
activityIdString- the id the app started the activity under
finalStateMap<String, ?>- the state to show as the activity ends, or null to leave the last one
dismissImmediatelyboolean- true to remove the activity now rather than letting the system keep the final state on screen for a while
Returns
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)Parameters
kindString- the widget kind the app declared
timelineJsonString- the timeline, already serialized as JSON
Returns
Builder.surface(Map)Throws
IllegalArgumentException- if either argument is empty