AdManagerInterstitialAd

public abstract class AdManagerInterstitialAd extends InterstitialAd


A full page ad experience at natural transition points such as a page change, an app launch, or a game level load for Google Ad Manager publishers. Interstitials use a close button that removes the ad from the user's experience.

Sample code:

public class MyActivity extends Activity {
    private AdManagerInterstitialAd adManagerInterstitialAd;
    private Button nextLevelButton;
    private TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create a full screen content callback.
        FullScreenContentCallback fullScreenContentCallback = new FullScreenContentCallback() {
            @Override
            public void onAdDismissedFullScreenContent() {
               adManagerInterstitialAd = null;
               // Proceed to the next level.
               goToNextLevel();
            }
        };

        // Load a Google Ad Manager interstitial ad. When a natural transition in the app occurs
        // (such as a level ending in a game), show the interstitial. In this simple example, the
        // press of a button is used instead.
        //
        // If the button is clicked before the interstitial is loaded, the user should proceed to
        // the next part of the app (in this case, the next level).
        //
        // If the interstitial is finished loading, the user will view the interstitial before
        // proceeding.
        AdManagerInterstitialAd.load(
            this,
            "myAdUnitId",
            new AdManagerAdRequest.Builder().build(),
            new AdManagerInterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull AdManagerInterstitialAd ad) {
                    adManagerInterstitialAd = ad;
                    adManagerInterstitialAd.setFullScreenContentCallback(
                        fullScreenContentCallback);
                }

                @Override
                public void onAdFailedToLoad(@NonNull LoadAdError adError) {
                    // Code to be executed when an ad request fails.
                }
            });

        // Create the button to go to the next level.
        nextLevelButton = new Button(this);
        nextLevelButton.setText("Next Level");
        nextLevelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Show the interstitial if it is ready. Otherwise, proceed to the next level
                // without ever showing it.
                if (adManagerInterstitialAd != null) {
                    adManagerInterstitialAd.show(MyActivity.this);
                } else {
                    // Proceed to the next level.
                    goToNextLevel();
                }
            }
        });

        // Add the next level button to the layout.
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(nextLevelButton);

        // Create a TextView to display the current level.
        textView = new TextView(this);
        textView.setText("Level 1");
        layout.addView(textView);

        setContentView(layout);
    }

    public void goToNextLevel() {
        // Show the next level, and disable the next level button since there are no more levels.
        nextLevelButton.setEnabled(false);
        textView.setText("Level 2");
    }
}

Summary

Public constructors

Public methods

abstract @Nullable AppEventListener

Returns the AppEventListener for this AdManagerInterstitialAd.

static void
load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdManagerAdRequest adManagerAdRequest,
    @NonNull AdManagerInterstitialAdLoadCallback loadCallback
)

Loads an AdManagerInterstitialAd.

abstract void

Sets an AppEventListener for this AdManagerInterstitialAd.

Inherited methods

From com.google.android.gms.ads.interstitial.InterstitialAd
abstract @NonNull String

Returns the ad unit ID.

abstract @Nullable FullScreenContentCallback

Gets the FullScreenContentCallback for this InterstitialAd.

abstract @Nullable OnPaidEventListener

Gets the OnPaidEventListener for this InterstitialAd.

abstract @NonNull ResponseInfo

Returns the ResponseInfo object for the loaded ad.

static boolean
isAdAvailable(@NonNull Context context, @NonNull String adUnitId)

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

static void
load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdRequest adRequest,
    @NonNull InterstitialAdLoadCallback loadCallback
)

Loads an InterstitialAd.

static @Nullable InterstitialAd
pollAd(@NonNull Context context, @NonNull String adUnitId)

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

abstract void

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 interstitial object will be displayed in immersive mode.

abstract void

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

abstract void
show(@NonNull Activity activity)

Shows the interstitial ad.

Public constructors

AdManagerInterstitialAd

public AdManagerInterstitialAd()

Public methods

getAppEventListener

public abstract @Nullable AppEventListener getAppEventListener()

Returns the AppEventListener for this AdManagerInterstitialAd.

load

public static void load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdManagerAdRequest adManagerAdRequest,
    @NonNull AdManagerInterstitialAdLoadCallback loadCallback
)

Loads an AdManagerInterstitialAd.

Parameters
@NonNull Context context

The context.

@NonNull String adUnitId

The ad unit ID.

@NonNull AdManagerAdRequest adManagerAdRequest

An ad request with targeting information.

@NonNull AdManagerInterstitialAdLoadCallback loadCallback

A callback to be invoked when a Google Ad Manager interstitial ad finishes loading.

setAppEventListener

public abstract void setAppEventListener(@Nullable AppEventListener appEventListener)

Sets an AppEventListener for this AdManagerInterstitialAd.