Loading MREC consists of several stages:

  1. Loading BidMachine BannerRequest
  2. Setting up AdManagerAdRequest according to loaded BidMachine BannerRequest
  3. Loading AdManagerAdView with configured AdManagerAdRequest
  4. Loading BidMachine BannerView
  5. Showing BidMachine BannerView



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 BannerSize.Size_300x250 and AdRequestListener.
Call request on the BannerRequest instance to start loading.
When the onRequestSuccess callback is triggered (it means that the request has been successfully loaded) - you can proceed to AdManagerAdRequest settings using BannerRequest.

// Create new BidMachine request
BannerRequest bannerRequest = new BannerRequest.Builder()
        .setListener(new BannerRequest.AdRequestListener() {
            public void onRequestSuccess(@NonNull BannerRequest bannerRequest,
                                         @NonNull AuctionResult auctionResult) {
                runOnUiThread(() -> loadAdManagerMrec());

// Request an ad from BidMachine without loading it

Setting up AdManagerAdRequest

Steps to set up AdManagerAdRequest by BidMachine BannerRequest:

  1. Create a new AdManagerAdRequest instance
AdManagerAdRequest adManagerAdRequest =
  1. Create a new AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();
  1. Fill an existing AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
    new AdManagerAdRequest.Builder();
AMBidMachineUtils.appendRequest(adManagerAdRequestBuilder, bannerRequest);
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();

Loading AdManagerAdView

BidMachine uses AppEventListener to receive mediation result. If data from it matches the expected result, then you need to start loading the BidMachine ad object; if data does not match - BidMachine has lost the mediation and the AdManagerAdView needed to be shown.
Also call notifyMediationWin/notifyMediationLoss on the BannerRequest instance when BidMachine wins/loses the mediation.

Use the AdManagerAdRequest that was created during the previous step to load the AdManagerAdView.

// Create new AdManagerAdView instance
AdManagerAdView adManagerAdView = new AdManagerAdView(...);
adManagerAdView.setAdListener(new AdListener() {
    public void onAdLoaded() {
        // Wait for AppEventListener#onAppEvent to fire to determine if BidMachine won.
        // It is recommended to add a timer to prevent mediation from stopping if BidMachine loses the mediation.
        // In this case, AppEventListener#onAppEvent will not fire.
adManagerAdView.setAppEventListener(new AppEventListener() {
    public void onAppEvent(@NonNull String key, @NonNull String value) {
        // Checking whether it is BidMachine or not
        if (AMBidMachineUtils.isBidMachineBanner(key)) {
            // Don't forget to stop a timer.

            // Notify BidMachine about win.

            // Load BidMachine ad object, before show BidMachine ad.

// Load AdManagerAdView with AdManagerAdRequest

Loading BidMachine BannerView

If BidMachine has won the mediation, the next step will be loading BidMachine BannerView.

BannerView bannerView = new BannerView(...);

Show BidMachine BannerView

After loading BidMachine BannerView, show it by adding it to ViewGroup.


Don't forget to check if it can be shown by calling canShow on the BannerView instance before showing

if (bannerView != null && bannerView.canShow()) {


Sample App

You can find Sample App with BidMachineSDK and Ad Manager here: Github