Class NotificationConfig

  • All Implemented Interfaces:

    
    public final class NotificationConfig
    
                        

    Configuration class for building Notifications. These setting will apply to all notifications generated by Marigold.

    • Constructor Detail

      • NotificationConfig

        NotificationConfig()
    • Method Detail

      • addNotificationExtender

         final NotificationConfig addNotificationExtender(NotificationCompat.Extender extender)

        Add your own notification extender to customise the look of received notifications <br></br> To customise the appearance or content of a notification, implement as many NotificationCompat.Extenders as you like <br></br> Having access to the NotificationCompat.Builder means you can change pretty much whatever you like about the style and content of the notification. Check out the Android Developer docs here for more info. <br></br><br></br> Note that if any extenders are added, they will by default override Marigold’s notification extender. If you’d like us to still do our default notification extension, you can manually re-extend using NotificationExtender <br></br><br></br> For example, if you want to change the title of push notifications with the custom field special_price, you could implement the following NotificationCompat.Extender:

        <pre> ` class SaleNotificationExtender: NotificationCompat.Extender { override extend(builder: NotificationCompat.Builder): NotificationCompat.Builder { val bundle = builder.getExtras() val context = builder.mContext if(bundle.containsKey("special_price")) { builder.setContentTitle("SALE") .setContentText(bundle.getString("alert")) } else { // keeping Marigold default behavior return builder.extend(NotificationExtender(context)) } return builder; } } ` * </pre> *

        <br></br><br></br> Then add it to our NotificationConfig using: notificationConfig.addNotificationExtender(SaleNotificationExtender()) <br></br><br></br> Note: Please don't set a PendingIntent using setContentIntent directly, as it's defined by Marigold so we can track opens properly. If you want to change the Intent to be executed when a notification is tapped use ContentIntentBuilder

        Parameters:
        extender - your Notification Extender
        Returns:

        The same NotificationConfig.

      • setDefaults

         final NotificationConfig setDefaults(Integer defaults)

        Set the default notification options that will be used. The value should be one or more of the following fields combined with a bitwise-or: Notification.DEFAULT_SOUND, Notification.DEFAULT_VIBRATE, Notification.DEFAULT_LIGHTS. For all default values, use Notification.DEFAULT_ALL.

        Parameters:
        defaults - Bitwise combination of default fields
        Returns:

        The same NotificationConfig.

      • setSmallIcon

         final NotificationConfig setSmallIcon(Integer icon)

        Set the small icon to use in the notification layouts. Different classes of devices may return different sizes. See the Android UX guidelines for more information on how to design these icons.

        Parameters:
        icon - A resource ID in the application's package of the drawable to use.
        Returns:

        The same NotificationConfig.

      • setLargeIcon

         final NotificationConfig setLargeIcon(@DrawableRes() Integer largeIcon)

        Set the large icon that is shown in the ticker and notification.

        Parameters:
        largeIcon - A resource ID in the application's package of the drawable to use.
        Returns:

        The same NotificationConfig.

      • setDefaultNotificationChannel

        @RequiresApi(value = 26) final NotificationConfig setDefaultNotificationChannel(NotificationChannel notificationChannel)

        Sets the notification channel on Oreo devices or later. Inaccessible pre-Oreo The NotificationChannel should be used for notification settings (vibration, sound, LED, etc) on devices >= Oreo instead of the options in this class, as it allows users more granular control of notification settings.

        Parameters:
        notificationChannel - the channel to use for Marigold notifications
        Returns:

        the same NotificationConfig.

      • setLights

         final NotificationConfig setLights(Integer argb, Integer onMs, Integer offMs)

        Set the argb value that you would like the LED on the device to blink, as well as the rate. The rate is specified in terms of the number of milliseconds to be on and then the number of milliseconds to be off.

        Parameters:
        argb - Color of the LED
        onMs - Number of Milliseconds on
        offMs - Number of milliseconds off
        Returns:

        The same NotificationConfig.

      • setSound

         final NotificationConfig setSound(Uri sound)

        Set the sound to play. It will play on the default stream. On some platforms, a notification that is noisy is more likely to be presented as a heads-up notification.

        Parameters:
        sound - Uri to the sound
        Returns:

        The same NotificationConfig.

      • setVibrate

         final NotificationConfig setVibrate(LongArray pattern)

        Set the vibration pattern to use. On some platforms, a notification that vibrates is more likely to be presented as a heads-up notification.

        Parameters:
        pattern - The vibrate pattern
        Returns:

        The same NotificationConfig.

      • setDefaultContentIntent

         final NotificationConfig setDefaultContentIntent(Intent contentIntent, Integer requestCode, Integer flags)

        Supply an Intent to send when the notification is tapped.

        Parameters:
        contentIntent - Explicit Intent of the Activity, Service, or BroadcastReceiver to be launched.
        requestCode - Private request code for the sender
        flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
        Returns:

        The same NotificationConfig.

      • addAction

         final NotificationConfig addAction(String category, @DrawableRes() Integer icon, CharSequence title, Intent actionIntent, Integer flags)

        Adds an Action to an action category.

        Calling addAction() more than once with the same category will add each Action to that category, allowing many actions to be attached to notification of that category.

        Parameters:
        category - identifier of the action category
        icon - icon to show for this action
        title - the title of the action
        actionIntent - the Intent to fire when users trigger this action
        flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
        Returns:

        The same NotificationConfig.

      • addAction

         final NotificationConfig addAction(String categoryName, @DrawableRes() Integer icon, CharSequence title, Intent actionIntent, RemoteInput remoteInput, Integer flags)

        Adds an Action to an action category.

        Calling addAction() more than once with the same category will add each Action to that category, allowing many actions to be attached to notification of that category.

        Parameters:
        categoryName - identifier of the action category
        icon - icon to show for this action
        title - the title of the action
        actionIntent - the Intent to fire when users trigger this action
        remoteInput - a RemoteInput to add to the action
        flags - May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
        Returns:

        The same NotificationConfig.