Skip to main content

amos_flutter_admob 2.0.0 copy "amos_flutter_admob: ^2.0.0" to clipboard
amos_flutter_admob: ^2.0.0 copied to clipboard

PlatformAndroid

AdMob provider adapter for the AMOS Flutter monetization SDK.

AMOS Flutter AdMob #

Android AdMob provider adapter for amos_flutter. AMOS core owns identity, sessions, cohorts, decisions, caps, and cooldowns. This package owns Google Mobile Ads initialization, loading, rendering, display callbacks, fallback, and rewards.

Requirements #

  • `amos_flutter: ^2.0.0
  • Android API 24 or newer
  • com.amostack:amos-sdk-admob:2.0.0 available from Maven Central
  • Google Mobile Ads SDK 25.4.0 (included transitively by this package)
  • An AdMob application ID in the host Android manifest

Install #

dependencies:
  amos_flutter: ^2.0.0
  amos_flutter_admob: ^2.0.0

Add the publisher's AdMob application ID to android/app/src/main/AndroidManifest.xml:

<application ...>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY" />
</application>

Initialize #

Initialize AMOS core first, then the provider adapter:

final state = await AmosClient.instance.initialize(
  const AmosConfiguration(
    apiKey: 'amos_api_key',
    appId: 'amos_app_id',
    externalUserId: 'stable_account_id',
  ),
);

await AmosAdMob.instance.initialize();

Remote AdMob IDs configured in AMOS are used automatically. For LOCAL or REMOTE_WITH_LOCAL_FALLBACK mode, pass optional local groups:

await AmosAdMob.instance.initialize(
  localConfig: const AmosAdMobConfig(
    interstitialGroups: {
      'default': AmosAdMobGroupConfig(
        unitIds: ['ca-app-pub-.../...'],
        preloadOnInit: true,
      ),
    },
    testDeviceIds: ['TEST_DEVICE_ID'],
  ),
);

Never ship Google's sample IDs or test-device configuration as production inventory.

Render only when the current AMOS decision enables banners:

if (state.decision.ads.bannerEnabled)
  AmosBannerAd(
    groupRef: 'default',
    onLoaded: () => debugPrint('Banner loaded'),
    onFailed: (error) => debugPrint(error),
  );

Supported sizes are banner, largeBanner, mediumRectangle, fullBanner, and leaderboard.

Interstitial #

final load = await AmosAdMob.instance.preloadInterstitial(groupRef: 'default');
if (load.loaded) {
  final result = await AmosAdMob.instance.showInterstitial(groupRef: 'default');
  debugPrint('Shown: ${result.shown}, dismissed: ${result.dismissed}');
}

Rewarded #

await AmosAdMob.instance.preloadRewarded();
final result = await AmosAdMob.instance.showRewarded();
if (result.rewardEarned) {
  grantReward();
}

Grant the reward only when rewardEarned is true.

Native and app-open requests #

The Kotlin adapter currently exposes policy-resolved native and app-open requests. The host renderer uses the returned unit ID and must record an app-open impression after display:

final native = await AmosAdMob.instance.getNativeRequest();
final appOpen = await AmosAdMob.instance.getAppOpenRequest();
if (appOpen != null) {
  // Render through the host's Google Mobile Ads integration.
  await AmosAdMob.instance.recordAppOpenShown(groupRef: appOpen.groupRef);
}

The repository-only example app exercises cohort resolution, banner rendering, interstitial and rewarded flows, request inspection, signals, and paywalls.