Rewarded Ads

Prerequisites

Display a rewarded ad in your app

Displaying a rewarded ad is a two-step process. First you should create and load your MobileFuseRewardedAd unit, then when you’re ready, call the showAd() method to display the ad.

  • Create an rewarded ad unit
  • Display the ad

Create a rewarded ad unit

The MobileFuseRewardedAd class provided by the MobileFuse SDK will handle the loading and display of the full-screen rewarded ads.

📘

Tip

To provide a good user experience, you should create and pre-load your rewarded ad units before you intend to show the rewarded ad. Once a rewarded ad unit is created and pre-loaded, you can display it instantly with the showAd() method. Having the ad preloaded will ensure that you’re ready to display the ad as soon as the opportunity occurs. However, please note that ads expire after 5 minutes (at which time you’ll need to request a new one), so plan accordingly.

First, create a new MobileFuseRewardedAd unit and keep a reference to it within the Activity that you want to use it:

private MobileFuseRewardedAd rewardedAd;

private void createRewardedAd() {
    String placementId = "000000";
    rewardedAd = new MobileFuseRewardedAd(this, placementId);
}
private var rewardedAd: MobileFuseRewardedAd? = null

private fun createRewardedAd() {
    val placementId = "000000"
    rewardedAd = MobileFuseRewardedAd(this, placementId)
}

📘

Note

Ensure that the SDK has fully initialized before creating your ad units. You can use the onInitSuccess callback as a good place to set up your ad units.

Next, add a listener - the listener will allow you to receive events from the ad unit.

rewardedAd.setListener(new MobileFuseRewardedAd.Listener() {
    @Override
    public void onUserEarnedReward() {
        // The user has watched this rewarded ad and earned the reward for doing so - you should
        // reward the user accordingly from this callback.
    }

    @Override
    public void onAdLoaded() {
        // Ad has loaded - you are able to show the ad after this callback is triggered
    }

    @Override
    public void onAdNotFilled() {
        // No ad is currently available to display to this user
    }

    @Override
    public void onAdClosed() {
        // The ad has been displayed and closed
    }

    @Override
    public void onAdRendered() {
        // Triggered when the ad begins to show to the user
    }

    @Override
    public void onAdClicked() {
        // Triggered when the ad is clicked by the user
    }

    @Override
    public void onAdExpired() {
        // Triggered when a loaded ad has expired - you should manually try to load a new ad here
    }

    @Override
    public void onAdError(AdError error) {
        // An error occurred with the ad, examine the `error` argument to determine what went wrong
    }
});
rewardedAd.setListener(object : MobileFuseRewardedAd.Listener {
    override fun onUserEarnedReward() {
        // The user has watched this rewarded ad and earned the reward for doing so - you should
        // reward the user accordingly from this callback.
    }

    override fun onAdLoaded() {
        // Ad has loaded - you are able to show the ad after this callback is triggered
    }

    override fun onAdNotFilled() {
        // No ad is currently available to display to this user
    }

    override fun onAdClosed() {
        // The ad has been displayed and closed
    }

    override fun onAdRendered() {
        // Triggered when the ad begins to show to the user
    }

    override fun onAdClicked() {
        // Triggered when the ad is clicked by the user
    }

    override fun onAdExpired() {
        // Triggered when a loaded ad has expired - you should manually try to load a new ad here
    }

    override fun onAdError(error: AdError) {
        // An error occurred with the ad, examine the `error` argument to determine what went wrong
    }
})

Finally, request that the ad is preloaded using the loadAd method:

rewardedAd.loadAd();
rewardedAd.loadAd()

Display the ad

Once the rewarded ad has triggered the onAdLoaded callback, you can then call showAd() to instantly display the ad:

rewardedAd.showAd();
rewardedAd.showAd()

You can also use isLoaded() to check whether the ad is ready to be displayed.

if (rewardedAd.isLoaded()) {
    // The ad is ready to be displayed!
}
if (rewardedAd.isLoaded) {
    // The ad is ready to be displayed!
}

📘

Note

Once you call showAd() on an instance, the loaded ad will be displayed. Since a loaded ad can only be displayed once, you must call loadAd() again once the ad is closed to get a new ad ready to display.

Reward the user

The onUserEarnedReward callback will fire when the ad has been viewed by the user for long enough to earn the reward. You should use this callback to grant the reward to your user:

@Override
public void onUserEarnedReward() {
    // The user has watched this rewarded ad and earned the reward for doing so - you should
    // reward the user accordingly from this callback.

    // For example:
    Player.addCoins(20);
}
override fun onUserEarnedReward() {
    // The user has watched this rewarded ad and earned the reward for doing so - you should
    // reward the user accordingly from this callback.

    // For example:
    Player.addCoins(20)
}

Sample Code