public abstract class

NotificationManager

extends Object
java.lang.Object
   ↳ com.salesforce.marketingcloud.notifications.NotificationManager

Summary

Nested Classes
interface NotificationManager.NotificationBuilder Provide your NotificationManager.NotificationBuilder in the NotificationCustomizationOptions when initializing the SDK via setNotificationCustomizationOptions(NotificationCustomizationOptions)
interface NotificationManager.NotificationChannelIdProvider Provide your NotificationManager.NotificationChannelIdProvider in the NotificationCustomizationOptions when initializing the SDK via setNotificationCustomizationOptions(NotificationCustomizationOptions)
interface NotificationManager.NotificationLaunchIntentProvider Provide your NotificationManager.NotificationLaunchIntentProvider in the NotificationCustomizationOptions when initializing the SDK via setNotificationCustomizationOptions(NotificationCustomizationOptions)
interface NotificationManager.NotificationMessageDisplayedListener  
interface NotificationManager.ShouldShowNotificationListener  
Constants
String DEFAULT_CHANNEL_ID The channel id of the default notification channel created be the SDK.
Public Constructors
NotificationManager()
Public Methods
abstract boolean areNotificationsEnabled()
Returns whether or not notifications are enabled.
static void cancelNotificationMessage(Context context, NotificationMessage message)
Will cancel the notification associated with the provided message.
static String createDefaultNotificationChannel(Context context)
Will create the default notification channel used by the SDK only if it does not already exist.
static String createDefaultNotificationChannel(Context context, boolean forceRecreate)
Will create the default notification channel used by the SDK.
abstract void disableNotifications()
Disables notifications in the SDK.
abstract void enableNotifications()
Enables notifications in the SDK.
static NotificationMessage extractMessage(Intent intent)
Extracts the NotificationMessage from the Intent.
static NotificationCompat.Builder getDefaultNotificationBuilder(Context context, NotificationMessage message, String channelId, int smallIconResId)
This method will build out a android.support.v4.app.NotificationCompat.Builder with the defaults typically used by the SDK.
static PendingIntent redirectIntentForAnalytics(Context context, PendingIntent openIntent, NotificationMessage message, boolean autoCancel)
Returns a PendingIntent that will redirect to our internal Service to handle notification opened analytics.
abstract void registerNotificationMessageDisplayedListener(NotificationManager.NotificationMessageDisplayedListener listener)
Registers the provided listener.
abstract void setShouldShowNotificationListener(NotificationManager.ShouldShowNotificationListener listener)
Set a Should Show Notification Listener that will be queried as to whether or not a given notification should be displayed by the SDK.
abstract void unregisterNotificationMessageDisplayedListener(NotificationManager.NotificationMessageDisplayedListener listener)
Unregisters the provided listener.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DEFAULT_CHANNEL_ID

The channel id of the default notification channel created be the SDK.

Constant Value: "com.salesforce.marketingcloud.DEFAULT_CHANNEL"

Public Constructors

public NotificationManager ()

Public Methods

public abstract boolean areNotificationsEnabled ()

Returns whether or not notifications are enabled.
If false then the user will not see any notifications. (Push, Geofence, or Beacon).

Returns
  • boolean The state of notifications, either enabled (true) or disabled (false)

public static void cancelNotificationMessage (Context context, NotificationMessage message)

Will cancel the notification associated with the provided message.

public static String createDefaultNotificationChannel (Context context)

Will create the default notification channel used by the SDK only if it does not already exist.

Parameters
context Context
Returns
  • The channel id of the created notification channel.

public static String createDefaultNotificationChannel (Context context, boolean forceRecreate)

Will create the default notification channel used by the SDK.

Parameters
context Context
forceRecreate It true, the SDK will create the channel even if it already exists. If you have provided localization for the SDK's channel name R.string.mcsdk_default_notification_channel_name then you will need to pass true when the user changes the language on their device.
Returns
  • The channel id of the created notification channel.

public abstract void disableNotifications ()

Disables notifications in the SDK. This does not disable any individual message type(Push, Geofence, or Beacon), but will simply prevent the notification from being shown on the device.

Consider only using this for short term disablement of notifications. If you're desire it to turn notifications off long-term then consider disabling each message type directly as that will prevent the device from receiving those messages in the first place.

public abstract void enableNotifications ()

Enables notifications in the SDK. This does not enable any individual message type(Push, Geofence, or Beacon), but will simply allow notifications to be shown on the device.
Notifications are enabled by default.

public static NotificationMessage extractMessage (Intent intent)

Extracts the NotificationMessage from the Intent.

Parameters
intent android.content.Intent used to launch Android component from a push open.

public static NotificationCompat.Builder getDefaultNotificationBuilder (Context context, NotificationMessage message, String channelId, int smallIconResId)

This method will build out a android.support.v4.app.NotificationCompat.Builder with the defaults typically used by the SDK. It will set the following:

  • title text
  • alert text
  • small icon
  • large icon
  • big image
  • sound (*Only works on devices prior to Android O*)

You will need to set the android.support.v4.app.NotificationCompat.Builder#setContentIntent(PendingIntent) and wrap the PendingIntent using redirectIntentForAnalytics(Context, PendingIntent, NotificationMessage, boolean) to receive open analytics when the notification is clicked.

Parameters
context The context provided by the SDK.
message The message provided by the SDK.
channelId The notification channel ID. If this channel does not exist then your notification will not be displayed on devices running Android O (Oreo) or newer.
smallIconResId The resource id for the small icon to be used in the notification.
Returns
  • A android.support.v4.app.NotificationCompat.Builder.

public static PendingIntent redirectIntentForAnalytics (Context context, PendingIntent openIntent, NotificationMessage message, boolean autoCancel)

Returns a PendingIntent that will redirect to our internal Service to handle notification opened analytics. Once the analytic has been logged it will redirect the application to the provided PendingIntent openIntent.

Parameters
context The context to use to create the android.app.PendingIntent
openIntent PendingIntent to be used when the notification is clicked.
message Message associated with the notification
autoCancel If true, the notification will be clear from the notification shade once it has been clicked

public abstract void setShouldShowNotificationListener (NotificationManager.ShouldShowNotificationListener listener)

Set a Should Show Notification Listener that will be queried as to whether or not a given notification should be displayed by the SDK. Setting the listener to null effectively clears the value within the SDK and returns message handling to its default behavior.

Parameters
listener an instance of the interface