Skip to content

Android Usage

Alessandro Morvillo edited this page Aug 2, 2026 · 1 revision

Android Usage

The Android implementation wraps the native Kotlin library and Google Mobile Ads SDK Next-Gen.

Packages and namespaces

For callbacks only:

<PackageReference Include="AMDevIT.Admob.Wrapper.Droid" Version="0.1.10" />

For the shared async and UMP extensions:

<PackageReference Include="AMDevIT.Admob.Wrapper" Version="0.1.10" />

Common namespaces:

using AMDevIT.Admob.Wrapper.Ads;
using AMDevIT.Admob.Wrapper.Extensions.Droid;
using AMDevIT.Admob.Wrapper.Listeners;

Manifest

Add the application ID inside the <application> element:

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

Do not install Xamarin.GooglePlayServices.Ads. The binding embeds the Next-Gen SDK and its required runtime artifacts. UMP is supplied through the official .NET binding dependency; it is not an explicit native Gradle dependency.

Consent and initialization

const string applicationId = "ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY";
AdMobManager manager = AdMobManager.Instance;

try
{
    ConsentGatheringResult consent = await manager.GatherConsentAsync(this);
    if (!consent.CanRequestAds)
        return;
}
catch (ConsentException exception) when (exception.CanRequestAds == true)
{
    // The refresh failed, but the previous state permits requests.
}

await manager.InitializeAsync(this.ApplicationContext!, applicationId);

For the complete privacy workflow, see Privacy and Consent UMP.

Banner

BannerAdWrapper banner = new(this, logger: null);
Android.Views.View view = await banner.LoadAsync(
    "ca-app-pub-3940256099942544/6300978111");

bannerContainer.AddView(view);

The native wrapper also exposes callback-based loading and adaptive-width loading for hosts that manage their own layout.

Interstitial

InterstitialAdWrapper interstitial = new();
interstitial.Load(
    "ca-app-pub-3940256099942544/1033173712",
    new AdLoadListener(),
    new AdEventListener());

if (interstitial.IsLoaded)
    interstitial.Show(this, loadListener: null);

Rewarded

RewardedAdWrapper rewarded = new();
rewarded.Load(
    "ca-app-pub-3940256099942544/5224354917",
    new AdLoadListener(),
    new AdEventListener());

if (rewarded.IsLoaded)
    rewarded.Show(this, new RewardListener());

The reward listener receives the reward type and amount. Grant the reward only from that callback.

App open

AppOpenAdWrapper appOpen = new();
appOpen.Load(
    "ca-app-pub-3940256099942544/9257395921",
    new AdLoadListener(),
    new AdEventListener());

if (appOpen.IsLoaded)
    appOpen.Show(this, loadListener: null);

Callbacks

The low-level listener interfaces include:

  • IOnInitializedListener;
  • IOnAdLoadedListener;
  • IOnAdEventListener;
  • IOnRewardEarnedListener;
  • consent information, consent form, and consent gathering listeners.

Keep listener and wrapper instances alive until the corresponding native operation completes.

Logging

Implement IDroidLogger and pass it to the manager or ad-wrapper constructor to receive native trace, debug, information, warning, error, and critical messages. MAUICross supplies this adapter automatically. See Logging and Diagnostics.

Lifecycle notes

  • Destroy banners when the owning Activity is destroyed.
  • Full-screen ads are one-shot; reload after dismissal.
  • Only request ads after UMP permits them.
  • Use the current Activity when presenting consent or full-screen UI.

Clone this wiki locally