RewardedAd

abstract class RewardedAd


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();
                    }
                });
        }
    }
}

Summary

Public constructors

Public functions

abstract Bundle!

Gets all available ad metadata for this RewardedAd.

abstract String

Returns the ad unit ID.

abstract FullScreenContentCallback?

Gets the FullScreenContentCallback for this RewardedAd.

abstract OnAdMetadataChangedListener?

Gets the OnAdMetadataChangedListener for this RewardedAd.

abstract OnPaidEventListener?

Gets the OnPaidEventListener for this RewardedAd.

abstract ResponseInfo

Returns the ResponseInfo object for the loaded ad.

abstract RewardItem

Gets reward item for the loaded rewarded ad.

java-static Boolean
isAdAvailable(context: Context, adUnitId: String)

Returns true if there is an available rewarded ad loaded from startPreload.

java-static Unit
load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: RewardedAdLoadCallback
)

Loads a RewardedAd.

java-static Unit
load(
    context: Context,
    adUnitId: String,
    adRequest: AdRequest,
    loadCallback: RewardedAdLoadCallback
)

Loads a RewardedAd.

java-static RewardedAd?
pollAd(context: Context, adUnitId: String)

Retrieves the next rewarded ad loaded from startPreload, or null if no ad is available.

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

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

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

Sets a flag that controls if this rewarded ad object will be displayed in immersive mode.

abstract Unit

Sets the OnAdMetadataChangedListener for this RewardedAd.

abstract Unit

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

abstract Unit

Sets ServerSideVerificationOptions for this RewardedAd.

abstract Unit
show(
    activity: Activity,
    onUserEarnedRewardListener: OnUserEarnedRewardListener
)

Shows the rewarded ad.

Public constructors

RewardedAd

RewardedAd()

Public functions

getAdMetadata

abstract fun getAdMetadata(): Bundle!

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 onAdMetadataChanged to listen for changes.

getAdUnitId

abstract fun getAdUnitId(): String

Returns the ad unit ID.

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

Gets the FullScreenContentCallback for this RewardedAd.

getOnAdMetadataChangedListener

abstract fun getOnAdMetadataChangedListener(): OnAdMetadataChangedListener?

Gets the OnAdMetadataChangedListener for this RewardedAd.

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

Gets the OnPaidEventListener for this RewardedAd.

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

Returns the ResponseInfo object for the loaded ad.

getRewardItem

abstract fun getRewardItem(): RewardItem

Gets reward item for the loaded rewarded ad.

isAdAvailable

java-static fun isAdAvailable(context: Context, adUnitId: String): Boolean

Returns true if there is an available rewarded ad loaded from startPreload.

load

java-static fun load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: RewardedAdLoadCallback
): Unit

Loads a RewardedAd.

Parameters
context: Context

The context.

adUnitId: String

The ad unit ID.

adManagerAdRequest: AdManagerAdRequest

A Google Ad Manager ad request with targeting information.

loadCallback: RewardedAdLoadCallback

A callback to be invoked when a rewarded ad finishes loading.

load

java-static fun load(
    context: Context,
    adUnitId: String,
    adRequest: AdRequest,
    loadCallback: RewardedAdLoadCallback
): Unit

Loads a RewardedAd.

Parameters
context: Context

The context.

adUnitId: String

The ad unit ID.

adRequest: AdRequest

An ad request with targeting information.

loadCallback: RewardedAdLoadCallback

A callback to be invoked when a rewarded ad finishes loading.

pollAd

java-static fun pollAd(context: Context, adUnitId: String): RewardedAd?

Retrieves the next rewarded ad loaded from startPreload, or null if no ad is available.

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

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

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

Sets a flag that controls if this rewarded ad object will be displayed in immersive mode. Call this method before show. During show, 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.

setOnAdMetadataChangedListener

abstract fun setOnAdMetadataChangedListener(listener: OnAdMetadataChangedListener?): Unit

Sets the OnAdMetadataChangedListener for this RewardedAd.

setOnPaidEventListener

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

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

setServerSideVerificationOptions

abstract fun setServerSideVerificationOptions(
    options: ServerSideVerificationOptions?
): Unit

Sets ServerSideVerificationOptions for this RewardedAd.

show

abstract fun show(
    activity: Activity,
    onUserEarnedRewardListener: OnUserEarnedRewardListener
): Unit

Shows the rewarded ad.

Parameters
activity: Activity

The activity from which the rewarded ad should be shown.

onUserEarnedRewardListener: OnUserEarnedRewardListener

The listener to be notified when user earns a reward.