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 ce InterstitialAd.

abstract @Nullable OnPaidEventListener

Récupère le OnPaidEventListener pour ce InterstitialAd.

abstract long

Renvoie l'ID d'emplacement pour cet objet InterstitialAd.

abstract @NonNull ResponseInfo

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

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

Cette méthode est obsolète.

Utilisez plutôt isAdAvailable.

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)

Cette méthode est obsolète.

Utilisez plutôt pollAd.

abstract void

Enregistre un rappel à invoquer lorsque des annonces affichent et ferment du contenu en plein écran.

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

Définit un indicateur qui détermine si cet objet interstitiel sera affiché en mode immersif.

abstract void

Enregistre un rappel à invoquer lorsque cette annonce est estimée avoir généré des revenus.

abstract void
setPlacementId(long placementId)

Définit un ID d'emplacement pour l'annonce interstitielle.

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 ce InterstitialAd.

getOnPaidEventListener

public abstract @Nullable OnPaidEventListener getOnPaidEventListener()

Récupère le OnPaidEventListener pour ce InterstitialAd.

getPlacementId

public abstract long getPlacementId()

Renvoie l'ID d'emplacement pour cet objet InterstitialAd.

getResponseInfo

public abstract @NonNull ResponseInfo getResponseInfo()

Renvoie l'objet ResponseInfo pour 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

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 à invoquer lorsqu'une annonce interstitielle a fini de se charger.

pollAd

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

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

setFullScreenContentCallback

public abstract void setFullScreenContentCallback(
    @Nullable FullScreenContentCallback fullScreenContentCallback
)

Enregistre un rappel à invoquer lorsque des annonces affichent et ferment du contenu en plein écran.

setImmersiveMode

public abstract void setImmersiveMode(boolean immersiveModeEnabled)

Définit un indicateur qui détermine si cet objet interstitiel sera affiché en mode immersif. Appelez cette méthode avant show. Pendant show, si ce flag est activé et que le mode immersif est pris en charge, 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 à invoquer lorsque cette annonce est estimée avoir généré des revenus.

setPlacementId

public abstract void setPlacementId(long placementId)

Définit un ID d'emplacement pour l'annonce interstitielle.

Pour vous assurer que cet ID d'emplacement est inclus dans les rapports, appelez cette méthode avant d'afficher l'annonce.

Paramètres
long placementId

Entier long fourni par l'UI AdMob pour l'emplacement configuré.

afficher

public abstract void show(@NonNull Activity activity)

Affiche l'annonce interstitielle.

Paramètres
@NonNull Activity activity

Contexte Activity à partir duquel l'annonce doit être présentée.