Advanced Push Notification Customization for the Android SDK

When providing a builder to the NotificationCustomizationOptions class, you’re responsible for managing all aspects of the notification’s display properties and tap actions, including Notification Channel creation, Launch Intent action, and so on.

You can access the NotificationCompat.Builder that would have been used by the SDK and use it as a baseline for modifications. Additionally, the SDK can create a default NotificationChannel for your application.

To have Marketing Cloud Engagement collect notification open analytics for your notifications, wrap your PendingIntent in the SDK’s analytics helper method NotificationManager.redirectForAnalytics().

Note

1SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
2  pushFeatureModuleConfig = PushFeatureConfig.builder().apply {
3    // Other configuration values
4    setNotificationCustomizationOptions(
5      NotificationCustomizationOptions.create { context, notificationMessage ->
6        val builder = NotificationManager.getDefaultNotificationBuilder(
7          context,
8          notificationMessage,
9          NotificationManager.createDefaultNotificationChannel(context),
10          R.drawable.ic_notification_icon
11        )
12        builder.setContentIntent(
13          NotificationManager.redirectIntentForAnalytics(
14            context,
15            PendingIntent.getActivity(
16              context,
17              Random().nextInt(),
18              Intent(context, MainActivity::class.java),
19              PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
20            ),
21            notificationMessage,
22            true
23          )
24        )
25      }
26    )
27  }.build()
28}) {
29  // Handle initialization status
30}
1SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
2  pushModuleConfig = MarketingCloudConfig.builder().apply {
3    // Other configuration values
4    setNotificationCustomizationOptions(
5      NotificationCustomizationOptions.create { context, notificationMessage ->
6        val builder = NotificationManager.getDefaultNotificationBuilder(
7          context,
8          notificationMessage,
9          NotificationManager.createDefaultNotificationChannel(context),
10          R.drawable.ic_notification_icon
11        )
12        builder.setContentIntent(
13          NotificationManager.redirectIntentForAnalytics(
14            context,
15            PendingIntent.getActivity(
16              context,
17              Random().nextInt(),
18              Intent(context, MainActivity::class.java),
19              PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
20            ),
21            notificationMessage,
22            true
23          )
24        )
25      }
26    )
27  }.build(applicationContext)
28}) {
29  // TODO handle initialization status
30}
1MarketingCloudSdk.init(applicationContext as Application, MarketingCloudConfig.builder().apply {
2  // Other configuration values
3  setNotificationCustomizationOptions(
4    NotificationCustomizationOptions.create { context, notificationMessage ->
5      val builder = NotificationManager.getDefaultNotificationBuilder(
6        context,
7        notificationMessage,
8        NotificationManager.createDefaultNotificationChannel(context),
9        R.drawable.ic_notification_icon
10      )
11      builder.setContentIntent(
12        NotificationManager.redirectIntentForAnalytics(
13          context,
14          PendingIntent.getActivity(
15            context,
16            Random().nextInt(),
17            Intent(context, MainActivity::class.java),
18            PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
19          ),
20          notificationMessage,
21          true
22        )
23      )
24    }
25  )
26}.build(applicationContext)) { status ->
27  // TODO Handle initialization status
28}