NotificationManager

Package: com.salesforce.marketingcloud.notifications

SDK Version: 11.0.0

Description 

An abstract class for managing push notifications in the Salesforce Marketing Cloud Android SDK.

Constructor 

1constructor()

Properties 

DEFAULT_CHANNEL_ID 

1val DEFAULT_CHANNEL_ID: String = "com.salesforce.marketingcloud.DEFAULT_CHANNEL"

The SDK’s default notification channel identifier.

DEFAULT_FOREGROUND_CHANNEL_ID 

1val DEFAULT_FOREGROUND_CHANNEL_ID: String = "com.salesforce.marketingcloud.DEFAULT_FOREGROUND_CHANNEL"

The SDK’s default foreground notification channel identifier.

Methods 

areNotificationsEnabled 

1abstract fun areNotificationsEnabled(): Boolean

Returns the current notification enablement status.

Returns: Boolean - true if notifications are enabled, false otherwise


enableNotifications 

1abstract fun enableNotifications()

Activates SDK notifications.


disableNotifications 

1abstract fun disableNotifications()

Deactivates SDK notifications.


createDefaultNotificationChannel 

1open fun createDefaultNotificationChannel(context: Context): String

Creates the SDK’s default channel if it doesn’t exist.

Parameters:

  • context: Context - The application context

Returns: String - The channel ID

1open fun createDefaultNotificationChannel(context: Context, forceRecreate: Boolean): String

Creates the SDK’s default channel, optionally forcing recreation.

Parameters:

  • context: Context - The application context
  • forceRecreate: Boolean - If true, recreates the channel even if it exists

Returns: String - The channel ID


createForegroundNotificationChannel 

1open fun createForegroundNotificationChannel(context: Context): String

Creates the foreground channel if it doesn’t exist.

Parameters:

  • context: Context - The application context

Returns: String - The foreground channel ID


cancelNotificationMessage 

1open fun cancelNotificationMessage(context: Context, message: NotificationMessage)

Dismisses the notification for the specified message.

Parameters:

  • context: Context - The application context
  • message: NotificationMessage - The notification message to cancel

extractMessage 

1open fun extractMessage(intent: Intent): NotificationMessage?

Retrieves the NotificationMessage from an Intent.

Parameters:

  • intent: Intent - The intent containing the notification message

Returns: NotificationMessage? - The extracted notification message, or null if not present


getDefaultNotificationBuilder 

1open fun getDefaultNotificationBuilder(
2    context: Context,
3    message: NotificationMessage,
4    channelId: String,
5    smallIconResId: Int
6): NotificationCompat.Builder

Constructs a Builder with SDK default settings.

Parameters:

  • context: Context - The application context
  • message: NotificationMessage - The notification message to display
  • channelId: String - The notification channel ID
  • smallIconResId: Int - Resource ID for the small icon

Returns: NotificationCompat.Builder - A configured notification builder


redirectIntentForAnalytics 

1open fun redirectIntentForAnalytics(
2    context: Context,
3    openIntent: PendingIntent,
4    message: NotificationMessage,
5    autoCancel: Boolean
6): PendingIntent

Creates a PendingIntent that routes through analytics tracking.

Parameters:

  • context: Context - The application context
  • openIntent: PendingIntent - The original intent to wrap
  • message: NotificationMessage - The notification message
  • autoCancel: Boolean - Whether to auto-cancel the notification

Returns: PendingIntent - A pending intent with analytics tracking

1open fun redirectIntentForAnalytics(
2    context: Context,
3    openIntent: PendingIntent,
4    message: NotificationMessage,
5    autoCancel: Boolean,
6    bundle: Bundle?
7): PendingIntent

Extended version accepting an optional Bundle parameter.

Parameters:

  • context: Context - The application context
  • openIntent: PendingIntent - The original intent to wrap
  • message: NotificationMessage - The notification message
  • autoCancel: Boolean - Whether to auto-cancel the notification
  • bundle: Bundle? - Optional bundle with additional data

Returns: PendingIntent - A pending intent with analytics tracking


registerNotificationMessageDisplayedListener 

1abstract fun registerNotificationMessageDisplayedListener(
2    listener: NotificationMessageDisplayedListener
3)

Adds a display listener to receive notification display events.

Parameters:

  • listener: NotificationMessageDisplayedListener - The listener to register

unregisterNotificationMessageDisplayedListener 

1abstract fun unregisterNotificationMessageDisplayedListener(
2    listener: NotificationMessageDisplayedListener
3)

Removes a display listener.

Parameters:

  • listener: NotificationMessageDisplayedListener - The listener to unregister

setShouldShowNotificationListener 

1abstract fun setShouldShowNotificationListener(
2    listener: ShouldShowNotificationListener?
3)

Sets a listener to control notification display decisions.

Parameters:

  • listener: ShouldShowNotificationListener? - The listener to set, or null to remove

Nested Interfaces 

NotificationBuilder 

Customizes notification creation via NotificationCustomizationOptions.

NotificationChannelIdProvider 

Supplies channel IDs via NotificationCustomizationOptions.

NotificationLaunchIntentProvider 

Provides launch intents via NotificationCustomizationOptions.

NotificationMessageDisplayedListener 

Receives notification display events.

ShouldShowNotificationListener 

Controls notification display logic.