InterstitialAd

public abstract class InterstitialAd extends Object
Known Direct Subclasses

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

Sample code:

 public class MyActivity extends Activity {
     private InterstitialAd interstitialAd;
     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() {
                interstitialAd = null;
                // Proceed to the next level.
                goToNextLevel();
             }
         };

         // Load an 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.
         InterstitialAd.load(
             this,
             "myAdUnitId",
             new AdRequest.Builder().build(),
             new InterstitialAdLoadCallback() {
                 @Override
                 public void onAdLoaded(@NonNull InterstitialAd ad) {
                     interstitialAd = ad;
                     interstitialAd.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 (interstitialAd != null) {
                     interstitialAd.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");
     }
 }

Public Constructor Summary

Public Method Summary

abstract String
getAdUnitId()
Returns the ad unit ID.
abstract FullScreenContentCallback
abstract OnPaidEventListener
abstract ResponseInfo
getResponseInfo()
Returns the ResponseInfo object for the loaded ad.
static void
load(Context context, String adUnitId, AdRequest adRequest, InterstitialAdLoadCallback loadCallback)
Loads an InterstitialAd.
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 interstitial object will be displayed in immersive mode.
abstract void
setOnPaidEventListener(OnPaidEventListener listener)
Registers a callback to be invoked when this ad is estimated to have earned money.
abstract void
show(Activity activity)
Shows the interstitial ad.

Inherited Method Summary

Public Constructors

public InterstitialAd ()

Public Methods

public abstract String getAdUnitId ()

Returns the ad unit ID.

public abstract FullScreenContentCallback getFullScreenContentCallback ()

public abstract OnPaidEventListener getOnPaidEventListener ()

Gets the OnPaidEventListener for this InterstitialAd.

public abstract ResponseInfo getResponseInfo ()

Returns the ResponseInfo object for the loaded ad. Returns null until the ad successfully loads.

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

Loads an InterstitialAd.

Parameters
context An activity or application context.
adUnitId The ad unit ID.
adRequest An ad request with targeting information.
loadCallback A callback to be invoked when an interstitial ad finishes loading.

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 interstitial object will be displayed in immersive mode. Call this method before show(Activity). During show(Activity), 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 interstitial ad.

public abstract void setOnPaidEventListener (OnPaidEventListener listener)

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

public abstract void show (Activity activity)

Shows the interstitial ad.

Parameters
activity An Activity context from which to present the ad.