SummaryNotificationFactory

Base class for customizing grouped notification summary appearance on Android 7.0 (Nougat) and higher.

When multiple push notifications are displayed with the same group ID, Android automatically collapses them into a single stacked notification. The summary notification appears at the top of the stack and provides an overview of all grouped notifications. This class allows you to customize the appearance of that summary notification.

Group Notifications Feature:

  • Only works on Android 7.0 (API 24) and higher
  • Requires enabling multi-notification mode in AndroidManifest.xml
  • Groups notifications by the "pw_group" attribute in push payload
  • Summary shows the total count and custom message
  • User can expand to see individual notifications

Registration: Custom summary factory must be registered in AndroidManifest.xml:


  <application>
      <!-- Enable multi-notification mode -->
      <meta-data
          android:name="com.pushwoosh.multi_notification_mode"
          android:value="true" />

      <!-- Register custom summary factory -->
      <meta-data
          android:name="com.pushwoosh.summary_notification_factory"
          android:value=".MySummaryNotificationFactory" />
  </application>

Quick Start - Basic customization:


  public class MySummaryNotificationFactory extends SummaryNotificationFactory {
      
      public String summaryNotificationMessage(int notificationsAmount) {
          // Customize summary text
          return notificationsAmount + " new messages";
      }

      
      public int summaryNotificationIconResId() {
          // Use custom icon for summary
          return R.drawable.ic_notification_stack;
      }

      
      public int summaryNotificationColor() {
          // Use brand color
          return 0xFF6200EE;
      }
  }

Example - E-commerce app with order grouping:


  public class OrderSummaryFactory extends SummaryNotificationFactory {
      
      public String summaryNotificationMessage(int notificationsAmount) {
          // Customize based on notification count
          if (notificationsAmount == 1) {
              return "1 order update";
          } else {
              return notificationsAmount + " order updates";
          }
      }

      
      public int summaryNotificationIconResId() {
          return R.drawable.ic_shopping_bag;
      }

      
      public int summaryNotificationColor() {
          return getApplicationContext()
              .getResources()
              .getColor(R.color.brand_primary);
      }

      
      public boolean autoCancelSummaryNotification() {
          // Dismiss summary when user taps it
          return true;
      }
  }

Example - Conditional summary display:


  public class SmartSummaryFactory extends SummaryNotificationFactory {
      
      public boolean shouldGenerateSummaryNotification() {
          // Check user preferences
          SharedPreferences prefs = getApplicationContext()
              .getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
          return prefs.getBoolean("enable_grouped_notifications", true);
      }

      
      public String summaryNotificationMessage(int notificationsAmount) {
          return notificationsAmount + " notifications";
      }

      
      public int summaryNotificationIconResId() {
          return -1; // Use default
      }

      
      public int summaryNotificationColor() {
          return -1; // Use default
      }
  }

Important Notes:

  • Your factory class MUST be public and have a public no-argument constructor
  • Multi-notification mode must be enabled for grouping to work
  • Summary notifications are only created on Android 7.0+
  • Group ID is specified in push payload with "pw_group" attribute

See also

Inheritors

Properties

Link copied to clipboard
protected val applicationContext: Context

Functions

Link copied to clipboard
Controls whether the summary notification automatically dismisses when the user taps it.
Link copied to clipboard
open fun getNotificationIntent(): Intent
Link copied to clipboard
fun onGenerateSummaryNotification(notificationsAmount: Int, notificationChannelId: String, groupId: String): Notification
Link copied to clipboard
Controls whether summary notifications should be generated at all.
Link copied to clipboard
Returns the accent color for the summary notification icon.
Link copied to clipboard
Returns the small icon resource ID for the summary notification.
Link copied to clipboard
abstract fun summaryNotificationMessage(notificationsAmount: Int): String
Returns the message text displayed in the summary notification.