Banner Ad

Below are the steps to load and render a banner Ad on your app

1

Create your AdRequestConfiguration

Java
AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");
2

Call loadAd() method as per below format

Java
AdSterAdLoader.Companion.builder().withAdsListener(new MediationAdListener() {
    @Override
    public void onBannerAdLoaded(@NonNull MediationBannerAd ad) {
        super.onBannerAdLoaded(ad);
        // Show banner ad here
    }

    @Override
    public void onFailure(@NonNull AdError adError) {
        // Handle failure here
    }
}).withAdsEventsListener(new AdEventsListener() {
    @Override
    public void onAdClicked() {
        //Handle ad click here
    }

    @Override
    public void onAdImpression() {
        //Handle ad impression here
    }

    @Override
    public void onAdRevenuePaid(double revenue, @NotNull String adUnitId,@NotNull String network) {
        // Callback which provides revenue and the network which provided it
    }
}).build().loadAd(configuration.build());
3

Inside the onBannerAdLoaded callback method invoke getView() method of MediationnBannerAd object to add an xGrowth banner view to the given layout as shown below

Java / Kotlin
container.removeAllViews();
container.addView(ad.getView());
4

Call MediationBannerAd.destroy() When activity/fragment is destroyed or detached.

Last updated