Android Reference

Full AMOS integration examples for publishers.

This page is the longer technical reference for Android teams. Use it when the main SDK page is not enough and you want fuller code examples for wrapper-serving or manual or hybrid integration across interstitial, banner, rewarded, native, and app-open ads.

Choose One

Artifacts

  • `com.yuktinai:amos-sdk-admob:1.0.4` for wrapper-serving AdMob integration.
  • `com.yuktinai:amos-sdk:1.0.4` for manual or hybrid integration.
  • If the app team is integrating AdMob for the first time, start with `amos-sdk-admob`.
  • Use decision-policy provider `admob` for wrapper serving and `none` for manual or hybrid serving.

Dependencies

Repository and dependency setup

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

dependencies {
    implementation("com.yuktinai:amos-sdk-admob:1.0.4")

    // Or manual / hybrid
    // implementation("com.yuktinai:amos-sdk:1.0.4")
    // implementation("com.google.android.gms:play-services-ads:25.4.0")
}

Initialize

Base SDK initialization

Monetization.init(
    context = applicationContext,
    apiKey = "YOUR_API_KEY",
    appId = "YOUR_APP_ID",
    userId = "publisher-user-123"
) {
    // Ready to use SDK helpers here
}

Important Note

Is `getState()` required?

  • No. `Monetization.init(...)` is required.
  • `Monetization.getState()` is optional.
  • AMOS already uses `allowedEvents` and `allowedMetrics` internally for helper methods like `trackEventIfAllowed(...)`, `trackMetricIfAllowed(...)`, `isEventAllowed(...)`, and `isMetricAllowed(...)`.
  • Use `getState()` only if your app wants to inspect segment or allowlist state for its own UI, debugging, or custom gating logic.
  • During QA, you can end the current session and call `Monetization.init(...)` again to force a fresh backend decision fetch.

Config Source

How the SDK chooses AdMob config

  • `LOCAL` is the default path for all publishers and uses app-provided `AdMobConfig` only.
  • `REMOTE` and `REMOTE_WITH_LOCAL_FALLBACK` are managed options enabled by Yuktinai.
  • `REMOTE` uses backend-managed app AdMob config only.
  • `REMOTE_WITH_LOCAL_FALLBACK` prefers remote config and falls back to app local config when remote config is empty or unavailable.
  • If you want remote-managed AdMob config for your app, contact Yuktinai first.

Publisher Operations

Remote AdMob config can be managed outside the app

Admin UI app settings
- admobConfigMode = LOCAL | REMOTE | REMOTE_WITH_LOCAL_FALLBACK
- guided remote AdMob group editor
- optional publisher self-service portal

Publisher self-service portal
- app-scoped admin-domain link
- registered publisher email + OTP
- guided remote AdMob group editor for one app only

Remote modes are enabled only for managed publisher rollouts.

Config

AdMobConfig with multiple custom groups

val adMobConfig = AdMobConfig(
    interstitialGroups = mapOf(
        AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/111"),
            preloadOnInit = true
        ),
        "interstitial_level_end" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/112", "ca-app-pub-xxx/113"),
            allowFallbackToDefault = true
        ),
        "interstitial_store_entry" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/114")
        )
    ),
    bannerGroups = mapOf(
        AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/221")
        ),
        "banner_content" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/222", "ca-app-pub-xxx/223"),
            allowFallbackToDefault = true
        ),
        "banner_home_header" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/224")
        )
    ),
    rewardedGroups = mapOf(
        AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/331"),
            preloadOnInit = true
        ),
        "rewarded_bonus_claim" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/332"),
            preloadOnInit = true,
            allowFallbackToDefault = true
        )
    ),
    nativeGroups = mapOf(
        AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/441")
        ),
        "native_feed_card" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/442", "ca-app-pub-xxx/443"),
            allowFallbackToDefault = true
        )
    ),
    appOpenGroups = mapOf(
        AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/551"),
            preloadOnInit = true
        ),
        "app_open_cold_start" to AdMobGroupConfig(
            unitIds = listOf("ca-app-pub-xxx/552"),
            preloadOnInit = true,
            allowFallbackToDefault = true
        )
    )
)

Optional Structure

Externalize AdMobConfig into its own provider

object PublisherAdMobConfigProvider {
    fun build(): AdMobConfig {
        return AdMobConfig(
            interstitialGroups = mapOf(
                AdMobConfig.DEFAULT_GROUP_REF to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/111"),
                    preloadOnInit = true
                ),
                "interstitial_level_end" to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/112"),
                    allowFallbackToDefault = true
                )
            ),
            bannerGroups = mapOf(
                "banner_content" to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/222")
                )
            ),
            rewardedGroups = mapOf(
                "rewarded_bonus_claim" to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/332"),
                    preloadOnInit = true
                )
            ),
            nativeGroups = mapOf(
                "native_feed_card" to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/442")
                )
            ),
            appOpenGroups = mapOf(
                "app_open_cold_start" to AdMobGroupConfig(
                    unitIds = listOf("ca-app-pub-xxx/552"),
                    preloadOnInit = true
                )
            )
        )
    }
}

Wrapper Example

Full `amos-sdk-admob` example

class MainActivity : AppCompatActivity() {
    private lateinit var bannerContainer: FrameLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bannerContainer = findViewById(R.id.bannerContainer)

        val adMobConfig = PublisherAdMobConfigProvider.build()
        // Required for LOCAL
        // Optional only if Yuktinai has enabled REMOTE for this app
        AmosAdMob.configure(adMobConfig)

        Monetization.init(
            context = this,
            apiKey = BuildConfig.AMOS_API_KEY,
            appId = BuildConfig.AMOS_APP_ID,
            userId = "publisher-user-123"
        ) {
            AmosAdMob.initialize(this)
        }

        findViewById<Button>(R.id.interstitialButton).setOnClickListener {
            AmosAdMob.showInterstitial(
                activity = this,
                groupRef = "interstitial_level_end",
                onShown = { },
                onDismissed = { },
                onFailed = { error ->
                    Log.w("AMOS", "Interstitial failed: $error")
                }
            )
        }

        findViewById<Button>(R.id.rewardedButton).setOnClickListener {
            AmosAdMob.showRewarded(
                activity = this,
                groupRef = "rewarded_bonus_claim",
                onRewardEarned = {
                    grantCoinsToUser()
                },
                onFailed = { error ->
                    Log.w("AMOS", "Rewarded failed: $error")
                }
            )
        }

        AmosAdMob.createBannerView(
            context = this,
            groupRef = "banner_content",
            container = bannerContainer,
            onLoaded = { },
            onFailed = { error ->
                Log.w("AMOS", "Banner failed: $error")
            }
        )

        val nativeRequest = AmosAdMob.getNativeRequest("native_feed_card")
        if (nativeRequest != null) {
            loadNativeAdWithYourRenderer(nativeRequest.unitId)
        }

        val appOpenRequest = AmosAdMob.getAppOpenRequest("app_open_cold_start")
        if (appOpenRequest != null) {
            loadAndShowAppOpenAd(appOpenRequest.unitId)
            AmosAdMob.recordAppOpenShown(appOpenRequest.groupRef)
        }
    }

    private fun grantCoinsToUser() {
        // Publisher reward logic
    }

    private fun loadNativeAdWithYourRenderer(unitId: String) {
        // Publisher NativeAd loading and layout rendering
    }

    private fun loadAndShowAppOpenAd(unitId: String) {
        // Publisher app-open loading and lifecycle-aware showing
    }
}

Wrapper usage

When to pass custom groups

  • Use `interstitial_level_end` when the app has a level-end style interruption point.
  • Use `banner_content` when the banner belongs inside content or feed surfaces.
  • Use `rewarded_bonus_claim` when the app wants a reward-based flow.
  • Use `native_feed_card` when your app renders native ad inventory in feed or card layouts.
  • Use `app_open_cold_start` when your app wants app-open inventory at cold start or return-to-app moments.
  • If you want generic fallback behavior, omit `groupRef` and let the SDK use `default`.

Manual Example

Manual or hybrid interstitial example

private var interstitialAd: InterstitialAd? = null
private val interstitialGroupRef = "interstitial_level_end"

fun preloadInterstitial(context: Context) {
    val request = Monetization.preloadAdMobInterstitial(interstitialGroupRef) ?: return

    InterstitialAd.load(
        context,
        request.unitId,
        AdRequest.Builder().build(),
        object : InterstitialAdLoadCallback() {
            override fun onAdLoaded(ad: InterstitialAd) {
                interstitialAd = ad
                Monetization.markAdMobInterstitialLoaded(request.groupRef, ad)
            }

            override fun onAdFailedToLoad(error: LoadAdError) {
                interstitialAd = null
                Monetization.markAdMobInterstitialLoadFailed(request.groupRef)
            }
        }
    )
}

More helper calls

Manual or hybrid banner, rewarded, native, and app-open examples

val bannerRequest = Monetization.getAdMobBannerRequest("banner_content")
val rewardedRequest = Monetization.preloadAdMobRewarded("rewarded_bonus_claim")
val nativeRequest = Monetization.getAdMobNativeRequest("native_feed_card")
val appOpenRequest = Monetization.getAdMobAppOpenRequest("app_open_cold_start")

// Later in your own ads layer:
Monetization.markAdMobBannerLoaded("banner_content", bannerView)
Monetization.markAdMobRewardedLoaded("rewarded_bonus_claim", rewardedAd)
Monetization.markAdMobNativeLoaded("native_feed_card", nativeAd)

// After a real show:
Monetization.recordAdMobRewardedShown("rewarded_bonus_claim")
Monetization.recordAdMobAppOpenShown("app_open_cold_start")