InterstitialAd

public abstract class InterstitialAd

Sous-classes directes connues
AdManagerInterstitialAd

Il s'agit d'annonces occupant tout l'écran et diffusées à des points de transition naturels, par exemple à un changement de page, au lancement d'une application ou au téléchargement d'un niveau de jeu pour les éditeurs Google Ad Manager.


Il s'agit d'annonces occupant tout l'écran et diffusées à des points de transition naturels, par exemple à un changement de page, au lancement d'une application ou au téléchargement d'un niveau de jeu. Elles comportent un bouton permettant à l'utilisateur de les fermer.

Exemple de 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");
    }
}

Résumé

Constructeurs publics

Méthodes publiques

abstract @NonNull String

Renvoie l'ID du bloc d'annonces.

abstract @Nullable FullScreenContentCallback

Récupère le FullScreenContentCallback pour cet objet InterstitialAd.

abstract @Nullable OnPaidEventListener

Récupère le OnPaidEventListener pour cet objet InterstitialAd.

abstract @NonNull ResponseInfo

Renvoie l'objet ResponseInfo de l'annonce chargée.

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

Renvoie true si une annonce interstitielle est disponible et chargée à partir de startPreload.

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

Charge un InterstitialAd.

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

Récupère la prochaine annonce interstitielle chargée à partir de startPreload ou de null si aucune annonce n'est disponible.

abstract void

Enregistre un rappel à appeler lorsque des annonces s'affichent et que le contenu plein écran est fermé.

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

Définit un indicateur qui contrôle si cet objet interstitiel s'affichera en mode immersif.

abstract void

Enregistre un rappel à appeler lorsque cette annonce aura généré des revenus estimés.

abstract void
show(@NonNull Activity activity)

Affiche l'annonce interstitielle.

Constructeurs publics

InterstitialAd

public InterstitialAd()

Méthodes publiques

getAdUnitId

public abstract @NonNull String getAdUnitId()

Renvoie l'ID du bloc d'annonces.

getFullScreenContentCallback

public abstract @Nullable FullScreenContentCallback getFullScreenContentCallback()

Récupère le FullScreenContentCallback pour cet objet InterstitialAd.

getOnPaidEventListener

public abstract @Nullable OnPaidEventListener getOnPaidEventListener()

Récupère le OnPaidEventListener pour cet objet InterstitialAd.

getResponseInfo

public abstract @NonNull ResponseInfo getResponseInfo()

Renvoie l'objet ResponseInfo de l'annonce chargée. Renvoie null jusqu'à ce que l'annonce soit chargée.

isAdAvailable

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

Renvoie true si une annonce interstitielle est disponible et chargée à partir de startPreload.

auto-infligée

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

Charge un InterstitialAd.

Paramètres
@NonNull Context context

Un contexte d'activité ou d'application.

@NonNull String adUnitId

ID du bloc d'annonces.

@NonNull AdRequest adRequest

Demande d'annonce avec des informations de ciblage.

@NonNull InterstitialAdLoadCallback loadCallback

Rappel à appeler une fois le chargement d'une annonce interstitielle terminé.

pollAd

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

Récupère la prochaine annonce interstitielle chargée à partir de startPreload ou de null si aucune annonce n'est disponible.

setFullScreenContentCallback

public abstract void setFullScreenContentCallback(
    @Nullable FullScreenContentCallback fullScreenContentCallback
)

Enregistre un rappel à appeler lorsque des annonces s'affichent et que le contenu plein écran est fermé.

setImmersiveMode

public abstract void setImmersiveMode(boolean immersiveModeEnabled)

Définit un indicateur qui contrôle si cet objet interstitiel s'affichera en mode immersif. Appelez cette méthode avant show. Pendant show, si cet indicateur est activé et que le mode immersif est compatible, SYSTEM_UI_FLAG_IMMERSIVE_STICKY et SYSTEM_UI_FLAG_HIDE_NAVIGATION seront activés pour l'annonce interstitielle.

setOnPaidEventListener

public abstract void setOnPaidEventListener(@Nullable OnPaidEventListener listener)

Enregistre un rappel à appeler lorsque cette annonce aura généré des revenus estimés.

afficher

public abstract void show(@NonNull Activity activity)

Affiche l'annonce interstitielle.

Paramètres
@NonNull Activity activity

Contexte Activity à partir duquel présenter l'annonce.