Documentation

Overview

Loading rewarded ad consists of several stages:

  1. Loading BidMachine RewardedRequest
  2. Setting up AdManagerAdRequest according to loaded BidMachine RewardedRequest
  3. Loading AdManager RewardedAd with configured AdManagerAdRequest
  4. Loading BidMachine RewardedAd
  5. Showing BidMachine RewardedAd

Loading BidMachine RewardedRequest

Create a new RewardedRequest instance with AdRequestListener.
Call request on the RewardedRequest 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 RewardedRequest.

// Create new BidMachine request
RewardedRequest rewardedRequest = new RewardedRequest.Builder()
        .setListener(new RewardedRequest.AdRequestListener() {
            @Override
            public void onRequestSuccess(@NonNull RewardedRequest rewardedRequest,
                                         @NonNull AuctionResult auctionResult) {
                runOnUiThread(() -> loadAdManagerRewarded());
            }
        })
        .build();

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

Setting up AdManagerAdRequest

Steps to set up AdManagerAdRequest by BidMachine RewardedRequest:

  1. Create new AdManagerAdRequest instance
AdManagerAdRequest adManagerAdRequest =
    AMBidMachineUtils.createAdManagerRequest(rewardedRequest);
  1. Create new AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
    AMBidMachineUtils.createAdManagerRequestBuilder(rewardedRequest);
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();
  1. Fill existing AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
    new AdManagerAdRequest.Builder();
AMBidMachineUtils.appendRequest(adManagerAdRequestBuilder, rewardedRequest);
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();

Loading AdManager RewardedAd

When configuring the AdManager RewardedAd, add an extra check to the top of onAdLoaded callback in the AdListener to determine if BidMachine has won/lost the mediation. Also, call notifyMediationWin/notifyMediationLoss on the RewardedRequest instance when BidMachine wins/loses the mediation.

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

RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
    @Override
    public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
        // Checking whether it is BidMachine or not
        if (AMBidMachineUtils.isBidMachineRewarded(rewardedAd)) {
            // Notify BidMachine about win
            bidMachineRewardedRequest.notifyMediationWin();

            // Load BidMachine ad object, before show BidMachine ad
            loadBidMachineRewarded();
        } else {
            // Notify BidMachine about loss
            bidMachineRewardedRequest.notifyMediationLoss();
        }
    }
};

RewardedAd.load(..., ..., adManagerAdRequest, adLoadCallback);

Loading BidMachine RewardedAd

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

RewardedAd rewardedAd = new RewardedAd(...);
rewardedAd.setListener(...);
rewardedAd.load(rewardedRequest);

Show BidMachine RewardedAd

After loading BidMachine RewardedAd, show it by calling show on the RewardedAd instance.

🚧

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

if (rewardedAd != null && rewardedAd.canShow()) {
    rewardedAd.show();
}

📘

Sample App

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