Interface IPushNotificationMessageBuilder
- All Known Implementing Classes:
PushMessageBuilder
public interface IPushNotificationMessageBuilder
A fluent builder for constructing a
IPushNotification.The builder is the sole way to create a notification. It is chainable — each setter returns this — and validates on build(), which produces an immutable notification and after which the builder should not be reused. A minimal notification requires only a title; everything else has a default (an empty options map, and the server-default TTL).
Obtain one from the engine, e.g. getPushNotificationEngine().newMessageBuilder(), so the builder is bound to the engine's settings for defaults such as TTL.
Example:
IPushNotification n = engine.newMessageBuilder()
.title("New message")
.body("You have 3 unread messages")
.icon("/icons/app-192.png")
.tag("inbox")
.data("threadId", "T-4417")
.timeToLive(3_600_000L) // one hour, in ms
.build();
- Author:
- IIZI
Method Summary
Modifier and TypeMethodDescriptionSets the notification badge URL (theoptions.badgefield) — the monochrome glyph a device shows in its status area.Sets the notification body (theoptions.bodyfield) — the secondary text shown beneath the title.build()Validates the accumulated fields and builds the immutable notification.Adds one key/value pair to the notification's application data (theoptions.dataobject), which the service worker receives verbatim and the application interprets.Sets the notification icon URL (theoptions.iconfield).Sets an arbitrary option directly into theoptionsmap, for fields not covered by a dedicated setter (e.g.Sets the notification tag (theoptions.tagfield).timeToLive(long millis) Sets this notification's time-to-live in milliseconds, overriding the server default.Sets the notification title (theshowNotificationtitle argument).
Method Details
title
Sets the notification title (theshowNotificationtitle argument). Required.- Parameters:
title- The title; must be non-null and non-empty.- Returns:
this, for chaining.
body
Sets the notification body (theoptions.bodyfield) — the secondary text shown beneath the title.- Parameters:
body- The body text.- Returns:
this, for chaining.
icon
Sets the notification icon URL (theoptions.iconfield).- Parameters:
iconUrl- The icon URL.- Returns:
this, for chaining.
badge
Sets the notification badge URL (theoptions.badgefield) — the monochrome glyph a device shows in its status area.- Parameters:
badgeUrl- The badge URL.- Returns:
this, for chaining.
tag
Sets the notification tag (theoptions.tagfield). Notifications sharing a tag coalesce on the device, replacing rather than stacking.- Parameters:
tag- The tag.- Returns:
this, for chaining.
data
Adds one key/value pair to the notification's application data (theoptions.dataobject), which the service worker receives verbatim and the application interprets. Repeated calls accumulate; a repeated key overwrites.- Parameters:
key- The data key; must be non-null.value- The data value.- Returns:
this, for chaining.
option
Sets an arbitrary option directly into theoptionsmap, for fields not covered by a dedicated setter (e.g.requireInteraction,silent,actions).- Parameters:
key- The option key; must be non-null.value- The option value.- Returns:
this, for chaining.
timeToLive
Sets this notification's time-to-live in milliseconds, overriding the server default. Clamped by the engine to the configured TTL range; a notification left without an explicit TTL usesIPushSettings.getDefaultTTL().- Parameters:
millis- The TTL in milliseconds.- Returns:
this, for chaining.
build
IPushNotification build()Validates the accumulated fields and builds the immutable notification.- Returns:
- The built
IPushNotification; nevernull. - Throws:
IllegalStateException- if a required field (the title) is missing or a field is invalid.