Class 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 Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe envelope schema this class writes. -
Method Summary
Modifier and TypeMethodDescriptionstatic PushNotification.Builderbuilder()A surface command that ends a Live Activity.liveUpdate(String activityId, Map<String, ?> state) A surface command that updates a running Live Activity.toJson()The envelope as JSON.toMap()The envelope as maps and lists, in the order the fields were set.A surface command that publishes new widget content.
-
Field Details
-
SCHEMA_VERSION
public static final int SCHEMA_VERSIONThe envelope schema this class writes.- See Also:
-
-
Method Details
-
builder
- Returns:
- a builder with the schema already set
-
toJson
The envelope as JSON.- Returns:
- the JSON object the service receives as
message
-
toMap
-
liveUpdate
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- the id the app started the activity understate- 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
PushNotification.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- the id the app started the activity underfinalState- the state to show as the activity ends, or null to leave the last onedismissImmediately- true to remove the activity now rather than letting the system keep the final state on screen for a while- Returns:
- a command for
PushNotification.Builder.surface(Map) - Throws:
IllegalArgumentException- if the id is empty or a state key is null
-
widget
A surface command that publishes new widget content.- Parameters:
kind- the widget kind the app declaredtimelineJson- the timeline, already serialized as JSON- Returns:
- a command for
PushNotification.Builder.surface(Map) - Throws:
IllegalArgumentException- if either argument is empty
-