Enabling rewarded ads

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 an object of the RewardedAd class.

    mRewardedAd = new RewardedAd(this);
  2. Set the Block ID using the setBlockId method.

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

  3. If you confirm the reward on the server side (“server-side-reward”), set the user ID.

    mRewardedAd.setUserId(USER_ID);
  4. 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 an object of the RewardedAd class, 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

After creating and configuring the object of the RewardedAd class, load 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 BLOCK_ID = "YOUR_BLOCK_ID";
    private RewardedAd mRewardedAd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        // Creating a RewardedAd instance.
        mRewardedAd = new RewardedAd(this);
        mRewardedAd.setBlockId(BLOCK_ID);
                
        // Creating an ad targeting object.
        final AdRequest adRequest = new AdRequest.Builder().build();
                
        // Registering a listener to track events that occur in the ad.
        mRewardedAd.setRewardedAdEventListener(new RewardedAdEventListener.SimpleRewardedAdEventListener() {
            @Override
            public void onLoaded() {
                mRewardedAd.show();
            }
        });
                
        // Loading the ad.
        mRewardedAd.loadAd(adRequest);
    }
}

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