Module: Toybox.Notifications

Overview

Since:

API Level 5.1.0

Supported Devices:

Requires Permission:

  • Notifications

Classes Under Namespace

Classes: NotificationMessage

Constant Summary

NotificationMessageType

Notification message types

Since:

API Level 5.1.0

Name Value Since Description See Also
NOTIFICATION_MESSAGE_TYPE_DISMISSED 1

API Level 5.1.0

The notification was dismissed by the user

NOTIFICATION_MESSAGE_TYPE_SELECTED 2

API Level 5.1.0

The notification action was selected by the user

Typedef Summary collapse

Instance Method Summary collapse

Typedef Details

Action as { :label as Lang.String, :data as Notifications.NotificationDataType }

A notification action

Since:

API Level 5.1.0

NotificationMessageCallback as Lang.Method(message as Notifications.NotificationMessage) as Void

Since:

API Level 5.1.0

ShowNotificationOptions as { :icon as WatchUi.BitmapResource or Graphics.BitmapReference or Lang.ResourceId, :body as Lang.String or Lang.ResourceId, :data as Notifications.NotificationDataType, :actions as Lang.Array<Notifications.Action>, :dismissPrevious as Lang.Boolean }

Notification options

Since:

API Level 5.1.0

Instance Method Details

registerForNotificationMessages(callback as Notifications.NotificationMessageCallback or Null) as Void

Register a callback for receiving notification messages.

The callback will be called once for each notification message. If there are messages queued for the app when this function is called, the callback will immediately be called once for each pending message.

Parameters:

Example:

using Communications;

// set up phoneMessageCallback
function notificationMessageCallback(aMessage as NotificationMessage) as Void {
   System.println(aMessage.type);
   System.println(aMessage.data);
   System.println(aMessage.action);
}

// register callback to start receiving notifications when users interact with notifications or toasts
Notifications.registerForNotificationMessages(self.method(:notificationMessageCallback));

Since:

API Level 5.1.0

showNotification(title as Lang.String or Lang.ResourceId, subTitle as Lang.String or Lang.ResourceId, options as Notifications.ShowNotificationOptions or Null) as Void

Push a notification to the display

Parameters:

  • title(Lang.String, Lang.ResourceId)

    The title of the notification.

  • subTitle(Lang.String, Lang.ResourceId)

    The subTitle of the notification.

  • options(Lang.Dictionary)

    A Dictionary of options.

    • :body(Lang.String, Lang.ResourceId)

      The body of the notification.

    • :data(Notifications.NotificationDataType)

      The data associated with the notification. Will be passed back to the application for context when a notification action is selected.

    • :icon(Graphics.BitmapType, Lang.ResourceId)

      The icon to display with this notification. If no icon is provided and the system requires an icon, the app icon will be used.

    • :actions(Lang.Array)

      An array of action strings to display, and the data for those strings when the action is selected. The selected action will be passed to the application for context when the notification action is selected.

    • :dismissPrevious(Lang.Boolean)

      If true, dismiss all prior notifications that the app has posted. Note that this defaults to true if not provided.

Example:

 Notifications.showNotification("Jeff", "Something Happened", {
     :icon => Rez.Drawables.EmergencyIcon,
     :data => {},
     :actions => [
        { :label => Rez.Strings.ReplyAction, :data => MY_NOTIFICATION_ID_REPLY },
        { :label => Rez.Strings.ForwardAction, :data => MY_NOTIFICATION_ID_FORWARD },
     ],
});

Since:

API Level 5.1.0


Generated Mar 4, 2025, 4:09:53 PM