InterstitialAd

abstract class InterstitialAd

Classi di sottoclasse dirette note
AdManagerInterstitialAd

Un'esperienza pubblicitaria a pagina intera in punti di transizione naturale, come un cambio pagina, il lancio di un'app o un caricamento di livelli di gioco per i publisher Google Ad Manager.


Un'esperienza pubblicitaria a pagina intera in punti di transizione naturale, come un cambio pagina, il lancio di un'app o un caricamento di livelli di gioco. Gli interstitial utilizzano un pulsante di chiusura che rimuove l'annuncio dall'esperienza utente.

Codice di esempio:

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

Riepilogo

Costruttori pubblici

Funzioni pubbliche

abstract String

Restituisce l'ID unità pubblicitaria.

abstract FullScreenContentCallback?

Recupera il FullScreenContentCallback per questo InterstitialAd.

abstract OnPaidEventListener?

Recupera il OnPaidEventListener per questo InterstitialAd.

abstract ResponseInfo

Restituisce l'oggetto ResponseInfo per l'annuncio caricato.

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

Questa funzione è deprecata.

Utilizza invece isAdAvailable.

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

Carica un InterstitialAd.

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

Questa funzione è deprecata.

Utilizza invece pollAd.

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

Registra un callback da chiamare quando gli annunci mostrano e ignorano i contenuti a schermo intero.

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

Imposta un flag che controlla se questo oggetto interstitial verrà visualizzato in modalità immersiva.

abstract Unit

Registra un callback da chiamare quando si stima che questo annuncio abbia generato entrate.

abstract Unit
show(activity: Activity)

Mostra l'annuncio interstitial.

Costruttori pubblici

InterstitialAd

InterstitialAd()

Funzioni pubbliche

getAdUnitId

abstract fun getAdUnitId(): String

Restituisce l'ID unità pubblicitaria.

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

Recupera il FullScreenContentCallback per questo InterstitialAd.

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

Recupera il OnPaidEventListener per questo InterstitialAd.

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

Restituisce l'oggetto ResponseInfo per l'annuncio caricato. Restituisce null finché l'annuncio non viene caricato correttamente.

isAdAvailable

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

Restituisce true se è disponibile un annuncio interstitial caricato da startPreload.

load

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

Carica un InterstitialAd.

Parametri
context: Context

Un contesto di attività o applicazione.

adUnitId: String

L'ID unità pubblicitaria.

adRequest: AdRequest

Una richiesta di annuncio con informazioni sul targeting.

loadCallback: InterstitialAdLoadCallback

Un callback da chiamare al termine del caricamento di un annuncio interstitial.

pollAd

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

Recupera l'annuncio interstitial successivo caricato da startPreload o null se non è disponibile alcun annuncio.

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

Registra un callback da chiamare quando gli annunci mostrano e ignorano i contenuti a schermo intero.

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

Imposta un flag che controlla se questo oggetto interstitial verrà visualizzato in modalità immersiva. Chiama questo metodo prima del giorno show. Durante show, se questo flag è attivo e la modalità immersiva è supportata, SYSTEM_UI_FLAG_IMMERSIVE_STICKY e SYSTEM_UI_FLAG_HIDE_NAVIGATION verranno attivati per l'annuncio interstitial.

setOnPaidEventListener

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

Registra un callback da chiamare quando si stima che questo annuncio abbia generato entrate.

mostra

abstract fun show(activity: Activity): Unit

Mostra l'annuncio interstitial.

Parametri
activity: Activity

Un contesto Activity da cui presentare l'annuncio.