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 Summary
Constructors Constructor Description NotificationConfig()
-
Method Summary
Modifier and Type Method Description final NotificationConfig
setSilencer(NotificationSilencer notificationSilencer)
If you want certain notifications to be silent set your implementation of NotificationSilencer 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. final Boolean
hasNotificationExtenders()
final NotificationConfig
setColor(Integer argb)
Sets color final NotificationConfig
setDefaults(Integer defaults)
Set the default notification options that will be used. final NotificationConfig
setSmallIcon(Integer icon)
Set the small icon to use in the notification layouts. final NotificationConfig
setLargeIcon(@DrawableRes() Integer largeIcon)
Set the large icon that is shown in the ticker and notification. final NotificationConfig
setDefaultNotificationChannel(NotificationChannel notificationChannel)
Sets the notification channel on Oreo devices or later. 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. final NotificationConfig
setSound(Uri sound)
Set the sound to play. final NotificationConfig
setVibrate(LongArray pattern)
Set the vibration pattern to use. final NotificationConfig
setDefaultContentIntent(Intent contentIntent, Integer requestCode, Integer flags)
Supply an Intent to send when the notification is tapped. final NotificationConfig
setContentIntentBuilder(ContentIntentBuilder contentIntentBuilder)
Supply a ContentIntentBuilder to be called when a notification is tapped final NotificationConfig
addAction(String category, @DrawableRes() Integer icon, CharSequence title, Intent actionIntent, Integer flags)
Adds an Action to an action category. final NotificationConfig
addAction(String categoryName, @DrawableRes() Integer icon, CharSequence title, Intent actionIntent, RemoteInput remoteInput, Integer flags)
Adds an Action to an action category. final NotificationConfig
addCategory(NotificationCategory category)
Adds an action category. -
-
Method Detail
-
setSilencer
final NotificationConfig setSilencer(NotificationSilencer notificationSilencer)
If you want certain notifications to be silent set your implementation of NotificationSilencer
- Returns:
the same notification config
-
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
<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> *special_price
, you could implement the following NotificationCompat.Extender:<br></br><br></br> Then add it to our NotificationConfig using:
notificationConfig.addNotificationExtender(SaleNotificationExtender())
<br></br><br></br> Note: Please don't set aPendingIntent
usingsetContentIntent
directly, as it's defined by Marigold so we can track opens properly. If you want to change theIntent
to be executed when a notification is tapped use ContentIntentBuilder- Parameters:
extender
- your Notification Extender- Returns:
The same NotificationConfig.
-
hasNotificationExtenders
final Boolean hasNotificationExtenders()
-
setColor
final NotificationConfig setColor(Integer argb)
Sets color
- Parameters:
argb
- The accent color to use- 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, useNotification.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 LEDonMs
- Number of Milliseconds onoffMs
- 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 senderflags
- 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.
-
setContentIntentBuilder
final NotificationConfig setContentIntentBuilder(ContentIntentBuilder contentIntentBuilder)
Supply a ContentIntentBuilder to be called when a notification is tapped
- 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 categoryicon
- icon to show for this actiontitle
- the title of the actionactionIntent
- the Intent to fire when users trigger this actionflags
- 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 categoryicon
- icon to show for this actiontitle
- the title of the actionactionIntent
- the Intent to fire when users trigger this actionremoteInput
- a RemoteInput to add to the actionflags
- 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.
-
addCategory
final NotificationConfig addCategory(NotificationCategory category)
Adds an action category.
- Parameters:
category
- The category to add to the configuration.- Returns:
The same NotificationConfig
-
-
-
-