Enabling rewarded ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

A rewarded ad is a configurable full-screen ad. The user gets a reward for viewing the ad.

To enable advertising:

Creating a rewarded ad

  1. Add a RewardedAd class object.

    mRewardedAd = new RewardedAd(this);
  2. Set the AdUnitId using the setAdUnitId method.

    mRewardedAd.setAdUnitId(AdUnitId);

    AdUnitId is a unique identifier in R-M-XXXXXX-Y format, which is assigned in the Partner interface.

  3. If you are assigning rewards on the application side (“client-side reward”), implement the onRewarded interface method. It is called when the impression is registered and the user can be rewarded for viewing the ad. Use this chance to give the reward to the app user.

After creating and configuring a RewardedAd class object, you need to install a listener of the RewardedAdEventListener interface for the ad object in order to track events (like opening or closing the ad, exiting the app, or loading the app successfully or unsuccessfully).

Loading ads

Note.

Any call of the Mobile Ads SDK should be made from the main thread.

After creating and configuring the RewardedAd class object, load the ads. To load an ad, use the loadAd method, which takes the AdRequest object as a parameter (or Builder, which optionally accepts ad targeting data).

Displaying ads

Rewarded ads are loaded in the background immediately after the loadAd method is called. To display rewarded ads, call the show method.

We recommend checking whether the ad has actually loaded. To do this, call the isLoaded method.

Note.

You don't need to check this if the show method is called after the onAdLoaded callback has been triggered.

Example of working with rewarded ads

The following code demonstrates how to create and configure a RewardedAd object, register the listener, and load and display the rewarded ad:

...
public class RewardedAdExample extends Activity {
    ...
    private static final String AdUnitId = "YOUR_AdUnitId";
    private RewardedAd mRewardedAd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        // Creating a RewardedAd instance.
        mRewardedAd = new RewardedAd(this);
        mRewardedAd.setAdUnitId(AdUnitId);
                
        // Creating an ad targeting object.
        final AdRequest adRequest = new AdRequest.Builder().build();
                
        // Registering a listener to track events in the ad.
        mRewardedAd.setRewardedAdEventListener(new RewardedAdEventListener() {
            @Override
            public void onLoaded() {
                mRewardedAd.show();
            }
            
            @Override
            public void onRewarded(final Reward reward) {
                ...
            }
            
            @Override
            public void onAdFailedToLoad(final AdRequestError adRequestError) {
                ...
            }
            
            @Override
            public void onAdShown() {
                ...
            }
            
            @Override
            public void onAdDismissed() {
                ...
            }
            
            @Override
            public void onLeftApplication() {
                ...
            }
            
            @Override
            public void onReturnedToApplication() {
                ...
            }
        });
                
        // Loading ads.
        mRewardedAd.loadAd(adRequest);
    }
}

If advertising is integrated this way, the ad unit appears after the app starts.

To see how the ad will be displayed in the app, use a demo AdUnitId:
  • demo-rewarded-yandex