Documentation

Overview

Loading banner ads consists of several stages:

  1. Loading BidMachine BannerRequest
  2. Setting up AdMob AdRequest by loaded BidMachine BannerRequest
  3. Loading AdMob AdView with configured AdMob AdRequest

❗️

Auto-Refresh

Auto-refresh is not supported. For this type of integration, all of the above steps must be repeated.

Loading BidMachine BannerRequest

Create a new BannerRequest instance with a specific BannerSize and AdRequestListener.
Execute request on the BannerRequest instance to start loading.
When the onRequestSuccess callback is triggered, it means that the request has been successfully loaded and you can proceed to AdMob AdRequest settings.

// Create new BidMachine BannerRequest instance
BannerRequest bannerRequest = new BannerRequest.Builder()
        .setSize(...)
        .setListener(new BannerRequest.AdRequestListener() {
            @Override
            public void onRequestSuccess(@NonNull BannerRequest bannerRequest,
                                         @NonNull AuctionResult auctionResult) {
                runOnUiThread(() -> loadAdMobBanner(bannerRequest));
            }
        })
        .build();

// Request an ad from BidMachine without loading it
bannerRequest.request(...);

Setting up AdMob AdRequest

Ways to set up AdMob AdRequest by BidMachine BannerRequest:

  1. Create a new AdMob AdRequest instance
AdRequest adRequest = BidMachineUtils.createAdRequest(bannerRequest);
  1. Create a new AdMob AdRequest.Builder instance
AdRequest.Builder adRequestBuilder =
    BidMachineUtils.createAdRequestBuilder(bannerRequest);
AdRequest adRequest = adRequestBuilder.build();
  1. Fill an existing AdMob AdRequest.Builder instance
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
BidMachineUtils.appendRequest(adRequestBuilder, bannerRequest);
AdRequest adRequest = adRequestBuilder.build();

Loading AdMob AdView

Use the AdMob AdRequest that was created during the previous step to load the AdMob AdView

// Create new AdView instance
AdView adView = new AdView(...);
adView.setLayoutParams(...);
adView.setAdUnitId(...);
adView.setAdSize(AdSize.BANNER);
adView.setAdListener(...);

// Load AdView with AdMob AdRequest
adView.loadAd(adRequest);

📘

Sample App

You can find Sample App with BidMachineSDK and AdMob here: Github Banner