PushMessage

open class PushMessage

Represents a push notification message received from Pushwoosh.

PushMessage is a data container that provides access to all information about a received push notification, including content (title, message, images), appearance settings (icons, colors, sounds), behavior flags (silent, local), and metadata. This class is used throughout the SDK to pass push notification data between components.

Key Features:

  • Content Access - Retrieve notification title, message, and images
  • Appearance Settings - Access icon URLs, colors, LED, sound, and vibration settings
  • Metadata - Get campaign ID, message ID, push hash, and custom data
  • Behavior Flags - Check if notification is silent or local
  • Notification Actions - Access action buttons configured in the push
  • Data Conversion - Convert to Bundle or JSON for processing

Common Use Cases:


  // 1. Handling push notification in NotificationServiceExtension
  public class MyNotificationExtension extends NotificationServiceExtension {
      
      protected boolean onMessageReceived(PushMessage message) {
          // Access notification content
          String title = message.getHeader();
          String text = message.getMessage();
          String customData = message.getCustomData();

          // Parse custom data for e-commerce app
          if (customData != null) {
              try {
                  JSONObject data = new JSONObject(customData);
                  String productId = data.optString("product_id");
                  double discount = data.optDouble("discount", 0);

                  // Update local database with product discount
                  updateProductDiscount(productId, discount);

                  Log.d("App", "Push for product: " + productId);
              } catch (JSONException e) {
                  Log.e("App", "Failed to parse custom data", e);
              }
          }

          // Don't show notification if app is in foreground
          if (isAppOnForeground()) {
              showInAppAlert(title, text);
              return true; // Suppress notification
          }

          return false; // Show notification
      }

      
      protected void onMessageOpened(PushMessage message) {
          // Track campaign analytics
          long campaignId = message.getCampaignId();
          long messageId = message.getMessageId();

          // Navigate based on custom data
          String customData = message.getCustomData();
          if (customData != null) {
              try {
                  JSONObject data = new JSONObject(customData);
                  String screen = data.optString("screen");

                  if ("product_details".equals(screen)) {
                      String productId = data.optString("product_id");
                      openProductScreen(productId);
                  }
              } catch (JSONException e) {
                  Log.e("App", "Failed to parse custom data", e);
              }
          }
      }
  }

  // 2. Checking notification appearance settings
  protected void logNotificationSettings(PushMessage message) {
      // Check if notification is silent (data-only)
      if (message.isSilent()) {
          Log.d("App", "Silent push received");
          processDataOnly(message.getCustomData());
          return;
      }

      // Check if notification is local
      if (message.isLocal()) {
          Log.d("App", "Local notification triggered");
      }

      // Get rich media URLs
      String largeIcon = message.getLargeIconUrl();
      String bigPicture = message.getBigPictureUrl();

      if (bigPicture != null) {
          Log.d("App", "Notification has big picture: " + bigPicture);
      }
  }

  // 3. Working with notification actions
  protected void handleNotificationActions(PushMessage message) {
      List<Action> actions = message.getActions();

      if (!actions.isEmpty()) {
          Log.d("App", "Notification has " + actions.size() + " action buttons");

          for (Action action : actions) {
              Log.d("App", "Action: " + action.getTitle() +
                           ", Type: " + action.getType());
          }
      }
  }

Important Notes:

  • PushMessage objects are created automatically by the SDK when processing push notifications
  • To receive PushMessage instances, extend NotificationServiceExtension and override callback methods
  • Custom data can be sent from Pushwoosh Control Panel in JSON format and accessed via getCustomData
  • Silent pushes (isSilent returns true) do not display notifications but can trigger background processing
  • Use toBundle or toJson to access the raw push payload if needed
  • Campaign tracking IDs (getCampaignId, getMessageId) are useful for analytics

See also

Constructors

Link copied to clipboard
constructor(extras: Bundle)
Creates a PushMessage from a push notification payload Bundle.

Properties

Link copied to clipboard
val actions: List<Action>
Link copied to clipboard
val badges: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open fun getCampaignId(): Long
Gets the campaign ID for this push notification.
Link copied to clipboard
Gets the message code for this push notification.
Link copied to clipboard
open fun getMessageId(): Long
Gets the unique message ID for this push notification.
Link copied to clipboard
Link copied to clipboard
Gets the Pushwoosh internal notification ID.
Link copied to clipboard
open fun getTag(): String
Link copied to clipboard
Link copied to clipboard
open fun isLocal(): Boolean
Checks if this is a local notification.
Link copied to clipboard
open fun isLockScreen(): Boolean
Link copied to clipboard
open fun isSilent(): Boolean
Checks if this is a silent (data-only) push notification.
Link copied to clipboard
open fun toBundle(): Bundle
Converts this push message to a Bundle.
Link copied to clipboard
open fun toJson(): JSONObject
Converts this push message to JSON.