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

abstract OnPaidEventListener?

Récupère le OnPaidEventListener pour ce InterstitialAd.

abstract Long

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

abstract ResponseInfo

Renvoie l'objet ResponseInfo pour 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 à invoquer lorsque des annonces affichent et ferment du contenu en plein écran.

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

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

abstract Unit

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

abstract Unit
setPlacementId(placementId: Long)

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

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

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

Récupère le OnPaidEventListener pour ce InterstitialAd.

getPlacementId

abstract fun getPlacementId(): Long

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

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

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

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

pollAd

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

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

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

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

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

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

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

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

setPlacementId

abstract fun setPlacementId(placementId: Long): Unit

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
placementId: Long

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

afficher

abstract fun show(activity: Activity): Unit

Affiche l'annonce interstitielle.

Paramètres
activity: Activity

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