Class PushNotification

java.lang.Object
com.codename1.backend.push.PushNotification

public final class PushNotification extends Object

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.

  • Field Details

    • SCHEMA_VERSION

      public static final int SCHEMA_VERSION
      The envelope schema this class writes.
      See Also:
  • 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 - the id the app started the activity under
      state - 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 under
      finalState - the state to show as the activity ends, or null to leave the last one
      dismissImmediately - 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

      public static Map<String,Object> widget(String kind, String timelineJson)
      A surface command that publishes new widget content.
      Parameters:
      kind - the widget kind the app declared
      timelineJson - the timeline, already serialized as JSON
      Returns:
      a command for PushNotification.Builder.surface(Map)
      Throws:
      IllegalArgumentException - if either argument is empty