RewardedAd

public abstract class RewardedAd extends Object

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

 public class MainActivity extends AppCompatActivity {

     private RewardedAd rewardedAd;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         FullScreenContentCallback fullScreenContentCallback =
             new FullScreenContentCallback() {
                 @Override
                 public void onAdShowedFullScreenContent() {
                     // Code to be invoked when the ad showed full screen content.
                 }

                 @Override
                 public void onAdDismissedFullScreenContent() {
                     rewardedAd = null;
                     // Code to be invoked when the ad dismissed full screen content.
                 }
             };

         RewardedAd.load(
             this,
             "adUnitId",
             new AdRequest.Builder().build(),
             new RewardedAdLoadCallback() {
                 @Override
                 public void onAdLoaded(RewardedAd ad) {
                     findViewById(R.id.display_button).setVisibility(View.VISIBLE);
                     rewardedAd = ad;
                     rewardedAd.setFullScreenContentCallback(fullScreenContentCallback);
                 }
             });
     }

     public void onDisplayButtonClicked(View view) {
         if (rewardedAd != null) {
             rewardedAd.show(
                 this,
                 new OnUserEarnedRewardListener() {
                     @Override
                     public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
                         Toast.makeText(
                             MainActivity.this,
                             "onRewarded! currency: "
                                 + rewardItem.getType() + "    amount: "
                                 + rewardItem.getAmount(), Toast.LENGTH_SHORT).show();
                     }
                 });
         }
     }
 }

Public Constructor Summary

Public Method Summary

abstract Bundle
getAdMetadata()
Gets all available ad metadata for this RewardedAd.
abstract String
getAdUnitId()
Returns the ad unit ID.
abstract FullScreenContentCallback
abstract OnAdMetadataChangedListener
abstract OnPaidEventListener
abstract ResponseInfo
getResponseInfo()
Returns the ResponseInfo object for the loaded ad.
abstract RewardItem
getRewardItem()
Gets reward item for the loaded rewarded ad.
static boolean
isAdAvailable(Context context, String adUnitId)
Returns true if there is an available rewarded ad loaded from MobileAds.startPreload(Context, List, PreloadCallback).
static void
load(Context context, String adUnitId, AdRequest adRequest, RewardedAdLoadCallback loadCallback)
Loads a RewardedAd.
static void
load(Context context, String adUnitId, AdManagerAdRequest adManagerAdRequest, RewardedAdLoadCallback loadCallback)
Loads a RewardedAd.
static RewardedAd
pollAd(Context context, String adUnitId)
Retrieves the next rewarded ad loaded from MobileAds.startPreload(Context, List, PreloadCallback), or null if no ad is available.
abstract void
setFullScreenContentCallback(FullScreenContentCallback fullScreenContentCallback)
Registers a callback to be invoked when ads show and dismiss full screen content.
abstract void
setImmersiveMode(boolean immersiveModeEnabled)
Sets a flag that controls if this rewarded ad object will be displayed in immersive mode.
abstract void
abstract void
setOnPaidEventListener(OnPaidEventListener listener)
Registers a callback to be invoked when this ad is estimated to have earned money.
abstract void
abstract void
show(Activity activity, OnUserEarnedRewardListener onUserEarnedRewardListener)
Shows the rewarded ad.

Inherited Method Summary

Public Constructors

public RewardedAd ()

Public Methods

public abstract Bundle getAdMetadata ()

Gets all available ad metadata for this RewardedAd. Ad metadata is empty if the loaded ad doesn't have metadata. Ad metadata may update after loading. Use OnAdMetadataChangedListener.onAdMetadataChanged() to listen for changes.

public abstract String getAdUnitId ()

Returns the ad unit ID.

public abstract FullScreenContentCallback getFullScreenContentCallback ()

public abstract OnAdMetadataChangedListener getOnAdMetadataChangedListener ()

public abstract OnPaidEventListener getOnPaidEventListener ()

Gets the OnPaidEventListener for this RewardedAd.

public abstract ResponseInfo getResponseInfo ()

Returns the ResponseInfo object for the loaded ad.

public abstract RewardItem getRewardItem ()

Gets reward item for the loaded rewarded ad.

public static boolean isAdAvailable (Context context, String adUnitId)

Returns true if there is an available rewarded ad loaded from MobileAds.startPreload(Context, List, PreloadCallback).

public static void load (Context context, String adUnitId, AdRequest adRequest, RewardedAdLoadCallback loadCallback)

Loads a RewardedAd.

Parameters
context The context.
adUnitId The ad unit ID.
adRequest An ad request with targeting information.
loadCallback A callback to be invoked when a rewarded ad finishes loading.

public static void load (Context context, String adUnitId, AdManagerAdRequest adManagerAdRequest, RewardedAdLoadCallback loadCallback)

Loads a RewardedAd.

Parameters
context The context.
adUnitId The ad unit ID.
adManagerAdRequest A Google Ad Manager ad request with targeting information.
loadCallback A callback to be invoked when a rewarded ad finishes loading.

public static RewardedAd pollAd (Context context, String adUnitId)

Retrieves the next rewarded ad loaded from MobileAds.startPreload(Context, List, PreloadCallback), or null if no ad is available.

public abstract void setFullScreenContentCallback (FullScreenContentCallback fullScreenContentCallback)

Registers a callback to be invoked when ads show and dismiss full screen content.

public abstract void setImmersiveMode (boolean immersiveModeEnabled)

Sets a flag that controls if this rewarded ad object will be displayed in immersive mode. Call this method before show(Activity, OnUserEarnedRewardListener). During show(Activity, OnUserEarnedRewardListener), if this flag is on and immersive mode is supported, SYSTEM_UI_FLAG_IMMERSIVE_STICKY & SYSTEM_UI_FLAG_HIDE_NAVIGATION will be turned on for the rewarded ad.

public abstract void setOnAdMetadataChangedListener (OnAdMetadataChangedListener listener)

public abstract void setOnPaidEventListener (OnPaidEventListener listener)

Registers a callback to be invoked when this ad is estimated to have earned money.

public abstract void setServerSideVerificationOptions (ServerSideVerificationOptions options)

public abstract void show (Activity activity, OnUserEarnedRewardListener onUserEarnedRewardListener)

Shows the rewarded ad.

Parameters
activity The activity from which the rewarded ad should be shown.
onUserEarnedRewardListener The listener to be notified when user earns a reward.