Required Methods for Button Actions

Marketers can configure the action that occurs when an end user taps a button on an in-app message. The SDK handles actions for Notification Settings and Location Settings, while actions for Web URL and App URL require that you implement UrlHandler as a new SDK initialization method.

These examples show how to configure the SDK to handle button clicks in in-app messages.

1SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
2  inAppMessagingFeatureModuleConfig = InAppMessagingFeatureConfig.builder().apply {
3    // Other configuration options
4    // Tell the SDK how to handle button clicks in an In-App Message
5    setUrlHandler { context, url, _ ->
6      getActivity(
7        context,
8        Random().nextInt(),
9        Intent(Intent.ACTION_VIEW, url.toUri()),
10        PendingIntent.FLAG_UPDATE_CURRENT
11      )
12    }
13  }.build()
14}) {
15  // TODO handle initialization status
16}
1SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
2    engagementModuleConfig = MarketingCloudConfig.builder().apply {
3        // Other configuration options
4        // Tell the SDK how to handle button clicks in an In-App Message
5        setUrlHandler(UrlHandler { context, url, _ ->
6            PendingIntent.getActivity(
7                context,
8                Random().nextInt(),
9                Intent(Intent.ACTION_VIEW, url.toUri()),
10                PendingIntent.FLAG_UPDATE_CURRENT
11            )
12        })
13    }.build(applicationContext)
14}) {
15    // TODO handle initialization status
16}
1SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
2  pushModuleConfig = MarketingCloudConfig.builder().apply {
3    setApplicationId("{mc_application_id}")
4    setAccessToken("{mc_access_token}")
5    setSenderId("{fcm_sender_id}")
6    setMarketingCloudServerUrl("{marketing_cloud_url}")
7    setMid("{mid}")
8    setNotificationCustomizationOptions("{your instance of NotificationCustomizationOptions}")
9
10    // Tell the SDK how to handle button clicks in an In-App Message
11    setUrlHandler(UrlHandler { context, url, _ ->
12      PendingIntent.getActivity(
13        context,
14        Random().nextInt(),
15        Intent(Intent.ACTION_VIEW, Uri.parse(url)),
16        PendingIntent.FLAG_UPDATE_CURRENT
17      )
18    })
19    // Other configuration options
20  }.build(applicationContext)
21}) {
22  // TODO handle initialization status
23}
1MarketingCloudSdk.init(applicationContext as Application, MarketingCloudConfig.builder().apply {
2  setApplicationId("{mc_application_id}")
3  setAccessToken("{mc_access_token}")
4  setSenderId("{fcm_sender_id}")
5  setMarketingCloudServerUrl("{marketing_cloud_url}")
6  setMid("{mid}")
7  setNotificationCustomizationOptions("{your instance of NotificationCustomizationOptions}")
8
9  // Tell the SDK how to handle button clicks in an In-App Message
10  setUrlHandler(UrlHandler { context, url, _ ->
11    PendingIntent.getActivity(
12      context,
13      Random().nextInt(),
14      Intent(Intent.ACTION_VIEW, Uri.parse(url)),
15      PendingIntent.FLAG_UPDATE_CURRENT
16    )
17  })
18
19  // Other configuration options
20
21}.build(applicationContext)) {
22  // TODO handle initialization status
23}