-
Notifications
You must be signed in to change notification settings - Fork 4
Jetpack Compose
Muhammad Hammad edited this page Nov 28, 2025
·
1 revision
AdManageKit provides first-class Jetpack Compose support with composable functions for all ad types, state management helpers, and programmatic native ad loading.
Library Version: v2.8.0
dependencies {
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit:v2.8.0'
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit-core:v2.8.0'
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit-compose:v2.8.0'
}@Composable
fun MyScreen() {
BannerAdCompose(
adUnitId = "ca-app-pub-xxx/yyy",
modifier = Modifier.fillMaxWidth()
)
}@Composable
fun MyScreen() {
NativeTemplateCompose(
adUnitId = "ca-app-pub-xxx/yyy",
template = NativeAdTemplate.MATERIAL3,
loadingStrategy = AdLoadingStrategy.HYBRID,
modifier = Modifier.fillMaxWidth()
)
}@Composable
fun MyScreen() {
// Small format
NativeBannerSmallCompose(
adUnitId = "ca-app-pub-xxx/yyy",
loadingStrategy = AdLoadingStrategy.HYBRID
)
// Medium format
NativeBannerMediumCompose(
adUnitId = "ca-app-pub-xxx/yyy",
loadingStrategy = AdLoadingStrategy.HYBRID
)
// Large format
NativeLargeCompose(
adUnitId = "ca-app-pub-xxx/yyy",
loadingStrategy = AdLoadingStrategy.HYBRID
)
}Build your own native ad UI:
@Composable
fun MyScreen() {
ProgrammaticNativeBannerMediumCompose(
adUnitId = "ca-app-pub-xxx/yyy",
onAdLoaded = { /* success */ },
onAdFailed = { /* error */ }
)
}@Composable
fun MyScreen() {
val showInterstitial = rememberInterstitialAd(
adUnitId = "ca-app-pub-xxx/yyy",
preloadAd = true,
onAdShown = { analytics.log("ad_shown") },
onAdDismissed = { navigateNext() },
onAdFailedToLoad = { error -> Log.e("Ad", error) }
)
Button(onClick = { showInterstitial() }) {
Text("Show Ad")
}
}Declarative effect-based approach:
@Composable
fun MyScreen() {
var showAd by remember { mutableStateOf(false) }
InterstitialAdEffect(
adUnitId = "ca-app-pub-xxx/yyy",
showMode = InterstitialShowMode.TIME,
maxDisplayCount = 5,
onAdDismissed = { navigateNext() }
)
Button(onClick = { showAd = true }) {
Text("Continue")
}
}Full state control:
@Composable
fun MyScreen() {
val adState = rememberInterstitialAdState("ca-app-pub-xxx/yyy")
// Load manually
LaunchedEffect(Unit) {
adState.loadAd()
}
// Check state
if (adState.isLoaded) {
Button(onClick = { adState.showAd() }) {
Text("Show Ad")
}
}
}Hide ads for premium users:
@Composable
fun MyScreen() {
ConditionalAd {
// Only shown if user hasn't purchased
NativeBannerMediumCompose(adUnitId = "ca-app-pub-xxx/yyy")
}
}Preload ads on screen entry:
@Composable
fun MyScreen() {
CacheWarmingEffect(
adUnitId = "ca-app-pub-xxx/yyy",
adType = AdType.INTERSTITIAL
)
// Your screen content
}| Function | Description |
|---|---|
BannerAdCompose |
Banner ad composable |
NativeTemplateCompose |
Native with templates |
NativeBannerSmallCompose |
Small native ad |
NativeBannerMediumCompose |
Medium native ad |
NativeLargeCompose |
Large native ad |
ProgrammaticNativeBannerMediumCompose |
Programmatic native |
ConditionalAd |
Conditional wrapper |
| Function | Description |
|---|---|
rememberInterstitialAd |
Returns show lambda |
rememberInterstitialAdState |
Returns full state |
InterstitialAdEffect |
Declarative effect |
CacheWarmingEffect |
Preload effect |
AdManageKitInitEffect |
Initialization effect |
| Mode | Description |
|---|---|
TIME |
Time-based trigger |
COUNT |
Count-based trigger |
FORCE |
Always show |
-
Preload early - Use
preloadAd = trueorCacheWarmingEffect - Use ConditionalAd - Respect premium users
-
Handle callbacks - Always handle
onAdDismissed -
Choose right helper -
rememberInterstitialAdfor simple cases - Match template - Use appropriate native template
@Composable
fun ContentScreen() {
val showInterstitial = rememberInterstitialAd(
adUnitId = stringResource(R.string.interstitial_ad),
preloadAd = true,
onAdDismissed = { /* navigate */ }
)
Column {
// Banner at top
ConditionalAd {
BannerAdCompose(adUnitId = stringResource(R.string.banner_ad))
}
// Content
LazyColumn {
items(articles) { article ->
ArticleItem(article)
}
// Native ad in feed
item {
ConditionalAd {
NativeTemplateCompose(
adUnitId = stringResource(R.string.native_ad),
template = NativeAdTemplate.LIST_ITEM
)
}
}
}
// Action button
Button(onClick = { showInterstitial() }) {
Text("Next Article")
}
}
}AdManageKit v3.3.4 | GitHub | API Docs | Report Issue | Buy me a coffee