In-App Messaging in Android Apps that use SDK Version 10

The processes for implementing and customizing in-app messaging have been updated in version 10 of the SDK. To upgrade your app to version 10 of the SDK, first update the initialization code. Then, use these code examples to update the in-app messaging code in your app.

Implement IAM on Android 

Use this code example to implement in-app messaging during SDK initialization.

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}

Optional Methods 

Use this code example to set the in-app message listener.

1MarketingCloudSdk.requestSdk { engagementSdk ->
2
3  engagementSdk.inAppMessageManager.setInAppMessageListener(object :
4    InAppMessageManager.EventListener {
5
6    override fun shouldShowMessage(message: InAppMessage): Boolean {
7
8      return if (shouldShowMessage /* Your Custom logic confirming to show in-app message */) {
9        true
10      } else {
11        // Store message id for later
12        val blockedMessageId = message.id
13        false
14      }
15    }
16
17    override fun didShowMessage(message: InAppMessage) = Unit
18    override fun didCloseMessage(message: InAppMessage) = Unit
19  })
20}

Prevent or Delay Message Display 

Use this code example to prevent or delay the display of an in-app message.

1MarketingCloudSdk.requestSdk { engagementSdk ->
2  engagementSdk.inAppMessageManager.showMessage(blockedMessageId)
3}

Customize Display 

Use this code example to customize the font used in an in-app message.

1MarketingCloudSdk.requestSdk { engagementSdk ->
2  engagementSdk.inAppMessageManager.setTypeface(appFontFace)
3}

Set Status Bar Color 

Use this code example to set the status bar color of an in-app message.

1MarketingCloudSdk.requestSdk { engagementSdk ->
2  engagementSdk.inAppMessageManager.setStatusBarColor(
3    ContextCompat.getColor(this as Context, R.color.colorPrimary)
4  )
5}