Android APIs
public interface

RewardedVideoAd

com.google.android.gms.ads.reward.RewardedVideoAd

Class Overview

This class is used to request and display a rewarded video.

 public class MainActivity extends ActionBarActivity implements RewardedVideoAdListener {

     private RewardedVideoAd mAd;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         mAd = MobileAds.getRewardedVideoAdInstance(this);
         mAd.setUserId("userId");
         mAd.setRewardedVideoAdListener(this);
         AdRequest adRequest = new AdRequest.Builder().build();
         mAd.loadAd("adUnitId", adRequest);
     }

     @Override
     public void onRewardedVideoAdLoaded() {
         findViewById(R.id.display_button).setVisibility(View.VISIBLE);
     }

     public void onDisplayButtonClicked(View view) {
         if (mAd.isLoaded()) {
             mAd.show();
         }
     }

     @Override
     public void onRewarded(RewardItem rewardItem) {
         Toast.makeText(
             this,
             "onRewarded! currency: "
                 + rewardItem.getType() + "  amount: "
                 + rewardItem.getAmount(), Toast.LENGTH_SHORT).show();
     }

     @Override
     public void onResume() {
         super.onResume();
         mAd.resume();
     }

     @Override
     public void onPause() {
         mAd.pause();
         super.onPause();
     }

     @Override
     public void onDestroy() {
         mAd.destroy();
         super.onDestroy();
     }
 }

Summary

Public Methods
abstract void destroy()
Destroys the RewardedVideoAd.
abstract RewardedVideoAdListener getRewardedVideoAdListener()
abstract String getUserId()
Returns the user id set by setUserId(String).
abstract boolean isLoaded()
Returns true if a rewarded video ad is available and is ready to be shown.
abstract void loadAd(String adUnitId, AdRequest adRequest)
Requests for a rewarded video ad.
abstract void pause()
Pauses any extra processing associated with this RewardedVideoAd.
abstract void resume()
Resumes an RewardedVideoAd.
abstract void setRewardedVideoAdListener(RewardedVideoAdListener listener)
abstract void setUserId(String userId)
Sets the user id of current user.
abstract void show()
Shows rewarded video ad if available.

Public Methods

public abstract void destroy ()

Destroys the RewardedVideoAd. This method should be called in the parent Activity's onDestroy() method.

public abstract RewardedVideoAdListener getRewardedVideoAdListener ()

public abstract String getUserId ()

Returns the user id set by setUserId(String).

public abstract boolean isLoaded ()

Returns true if a rewarded video ad is available and is ready to be shown.

public abstract void loadAd (String adUnitId, AdRequest adRequest)

Requests for a rewarded video ad.

public abstract void pause ()

Pauses any extra processing associated with this RewardedVideoAd. This method should be called in the parent Activity's onPause() method.

public abstract void resume ()

Resumes an RewardedVideoAd. This method should be called in the parent Activity's onResume() method.

public abstract void setRewardedVideoAdListener (RewardedVideoAdListener listener)

public abstract void setUserId (String userId)

Sets the user id of current user.

This method is required for applications using server-to-server callbacks to reward users. This user id should uniquely identify a user, and is passed back as part of a server-to-server callback.

public abstract void show ()

Shows rewarded video ad if available. Applications should check isLoaded() before calling this method.