Rewarded

Integration

Just as interstitials, rewarded ads can only be integrated with code. Below we show a simple example to understand how it works:

public class MainActivity extends Activity {

    private RewardedAd mRewarded;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        mRewarded = new RewardedAd(this, "Wortise Ad Unit ID");
        mRewarded.loadAd();
    }
    
    @Override
    public void onDestroy() {
        ...
        mRewarded.destroy();
    }
    
    public void showInterstitial() {
        if (mRewarded.isAvailable()) {
            mRewarded.showAd(this);
        }
    }
}

Listener configuration

Like occurs with other formats, a listener can be set to receive the events that happen during the rewarded lifecycle. For this, it is needed to implement the RewardedAd.Listener interface just as shown in the example below:

mRewarded.setListener(new RewardedAd.Listener() {
    @Override
    public void onRewardedClicked(@NonNull RewardedAd ad) {
        // Invoked when the ad has been clicked
    }
    
    @Override
    public void onRewardedCompleted(@NonNull RewardedAd ad,
                                    @NonNull Reward reward) {
        // Invoked when the ad has been completed
    }
    
    @Override
    public void onRewardedDismissed(@NonNull RewardedAd ad) {
        // Invoked when the ad has been dismissed
    }
    
    @Override
    public void onRewardedFailedToLoad(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invoked when the ad could not be loaded
        // (because of an error or no fill)
    }

    @Override
    public void onRewardedFailedToShow(@NonNull RewardedAd ad,
                                       @NonNull AdError error) {
        // Invoked when the ad could not be shown
    }
    
    @Override
    public void onRewardedImpression(@NonNull RewardedAd ad) {
        // Invoked when the ad has generated an impression
    }
    
    @Override
    public void onRewardedLoaded(@NonNull RewardedAd ad) {
        // Invoked when the ad has been loaded
    }
    
    @Override
    public void onRewardedShown(@NonNull RewardedAd ad) {
        // Invoked when the ad has been shown
    }
});

Última actualización