InterstitialAd

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

Fonctions publiques

abstract String

Renvoie l'ID du bloc d'annonces.

abstract FullScreenContentCallback?

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

abstract OnPaidEventListener?

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

abstract ResponseInfo

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

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

Cette fonction est obsolète.

Utilisez plutôt isAdAvailable.

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

Charge un InterstitialAd.

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

Cette fonction est obsolète.

Utilisez plutôt pollAd.

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

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

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

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

abstract Unit

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

abstract Unit
show(activity: Activity)

Affiche l'annonce interstitielle.

Constructeurs publics

InterstitialAd

InterstitialAd()

Fonctions publiques

getAdUnitId

abstract fun getAdUnitId(): String

Renvoie l'ID du bloc d'annonces.

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

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

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

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

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

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

isAdAvailable

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

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

auto-infligée

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

Charge un InterstitialAd.

Paramètres
context: Context

Un contexte d'activité ou d'application.

adUnitId: String

ID du bloc d'annonces.

adRequest: AdRequest

Demande d'annonce avec des informations de ciblage.

loadCallback: InterstitialAdLoadCallback

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

pollAd

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

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

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

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

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

Définit un indicateur qui contrôle si cet objet interstitiel s'affichera en mode immersif. Appelez cette méthode avant show. Lors de 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

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

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

afficher

abstract fun show(activity: Activity): Unit

Affiche l'annonce interstitielle.

Paramètres
activity: Activity

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