PushwooshNotificationFactory

Default implementation of NotificationFactory provided by the Pushwoosh SDK.

This class serves as the reference implementation for creating push notifications with standard Pushwoosh features. It demonstrates best practices for building notifications and handling all notification data from the push payload, including rich media, actions, channels, and notification customization options.

Use this class as a starting point when creating your own custom notification factory. You can extend it and override specific methods to customize particular aspects while keeping the rest of the default behavior.

Features Implemented:

  • Large icon loading from URLs
  • Big picture style notifications with image loading
  • Notification channels (Android 8.0+)
  • Custom colors, priorities, and visibility settings
  • Notification actions from push payload
  • Sound, vibration, and LED from push payload
  • HTML formatted text support
  • Group notifications support (Android 7.0+)

Quick Start - Use as reference:


  // This is the default factory - no registration needed
  // Pushwoosh uses this automatically if no custom factory is specified

  // To see how it works, look at onGenerateNotification() method

Example - Extend for customization:


  public class MyNotificationFactory extends PushwooshNotificationFactory {
      
      public Notification onGenerateNotification(@NonNull PushMessage data) {
          // Call parent to get default notification
          Notification notification = super.onGenerateNotification(data);

          if (notification != null) {
              // Add custom modifications
              notification.flags |= Notification.FLAG_INSISTENT; // Keep alerting
          }

          return notification;
      }

      
      protected Bitmap getLargeIcon(PushMessage pushData) {
          // Use custom image loading library
          String iconUrl = pushData.getLargeIconUrl();
          if (iconUrl != null) {
              return MyImageLoader.loadSync(iconUrl);
          }
          return super.getLargeIcon(pushData);
      }
  }

  // Register in AndroidManifest.xml:
  <meta-data
      android:name="com.pushwoosh.notification_factory"
      android:value=".MyNotificationFactory" />

Example - Override for complete custom behavior:


  public class MyNotificationFactory extends PushwooshNotificationFactory {
      
      public Notification onGenerateNotification(@NonNull PushMessage data) {
          // Don't call super - build completely custom notification
          String channelId = addChannel(data);

          NotificationCompat.Builder builder = new NotificationCompat.Builder(
              getApplicationContext(), channelId)
              .setContentTitle(data.getHeader())
              .setContentText(data.getMessage())
              .setSmallIcon(R.drawable.custom_icon)
              .setColor(0xFF6200EE);

          Notification notification = builder.build();
          addCancel(notification);

          return notification;
      }
  }

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
protected val applicationContext: Context

Functions

Link copied to clipboard
protected fun addCancel(notification: Notification)
Makes the notification automatically dismiss when the user taps it.
Link copied to clipboard
protected open fun addChannel(pushMessage: PushMessage): String
Creates a notification channel for the push message if it doesn't already exist.
Link copied to clipboard
protected fun addLED(notification: Notification, color: Integer, ledOnMs: Int, ledOffMs: Int)
Adds LED blinking effect to the notification.
Link copied to clipboard
protected fun addSound(notification: Notification, sound: String)
Adds a sound to the notification.
Link copied to clipboard
protected fun addVibration(notification: Notification, vibration: Boolean)
Adds vibration to the notification.
Link copied to clipboard
open fun channelDescription(channelName: String): String
Provides a description for a notification channel.
Link copied to clipboard
open fun channelName(channelName: String): String
Customizes the display name of a notification channel.
Link copied to clipboard
protected open fun getBigPicture(pushData: PushMessage): Bitmap
Loads and returns the big picture image for expanded notification style.
Link copied to clipboard
protected fun getContentFromHtml(content: String): CharSequence
Converts HTML-formatted string to styled CharSequence for display in notifications.
Link copied to clipboard
protected open fun getLargeIcon(pushData: PushMessage): Bitmap
Loads and returns the large icon image for the notification.
Link copied to clipboard
open fun getNotificationIntent(data: PushMessage): Intent
Creates the intent that will be fired when the user taps the notification.
Link copied to clipboard
open fun onGenerateNotification(pushData: PushMessage): Notification
Creates and configures a notification from push message data.