A Kotlin SDK that lets you integrate Kontext ads into your Android app
mavenCentral()
. Ensure mavenCentral()
is listed in your project’s repository configuration.
build.gradle.kts
file:
AdsProvider
using the Builder
. This object should be scoped to a single conversation and ideally tied to a lifecycle-aware component, like a ViewModel
.
MessageRepresentable
You can make your existing message data class conform to the MessageRepresentable
interface. This involves overriding the required properties to map to your class’s fields.
AdsMessage
Data Class
If you cannot or prefer not to modify your existing data class, you can map your message objects to the AdsMessage
type provided by the SDK. AdsMessage
already conforms to MessageRepresentable
.
AdsProvider
.
The adsProvider.ads
property is a kotlinx.coroutines.flow.Flow
that emits a Map<String, List<AdConfig>>
. The map’s key is the message ID, and the value is a list of ads to be displayed for that message.
Collect this flow from a CoroutineScope
to receive and display ads.
InlineAd
composable is provided for this purpose. It takes an AdConfig
object and handles the ad rendering.
close()
method when the AdsProvider
is no longer needed.
AdsProvider
into an Android ViewModel
. For a complete, working implementation, please see the example
module in this repository.