InterstitialAd

abstract class InterstitialAd

Subclasses diretas conhecidas
AdManagerInterstitialAd

Uma experiência de anúncio de página inteira em pontos de transição naturais, como a mudança de página, a abertura de um aplicativo ou um carregamento de nível de jogo para editores do Google Ad Manager.


Uma experiência de anúncio de página inteira em pontos de transição naturais, como a mudança de página, a abertura de um aplicativo ou um carregamento de nível de jogo. Os anúncios intersticiais usam um botão "Fechar" que remove o anúncio da experiência do usuário.

Código de exemplo:

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

Resumo

Construtores públicos

Funções públicas

abstract String

Retorna o ID do bloco de anúncios.

abstract FullScreenContentCallback?

Recebe o FullScreenContentCallback para este InterstitialAd.

abstract OnPaidEventListener?

Recebe o OnPaidEventListener para este InterstitialAd.

abstract Long

Retorna o ID da posição para este InterstitialAd.

abstract ResponseInfo

Retorna o objeto ResponseInfo do anúncio carregado.

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

Essa função foi descontinuada.

Use isAdAvailable em vez disso.

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

Carrega um InterstitialAd.

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

Essa função foi descontinuada.

Use pollAd.

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

Registra um callback a ser invocado quando os anúncios mostram e dispensam conteúdo em tela cheia.

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

Define uma flag que controla se esse objeto intersticial será exibido no modo imersivo.

abstract Unit

Registra um callback para ser invocado quando se estima que o anúncio gerou receita.

abstract Unit
setPlacementId(placementId: Long)

Define um ID de posição para o anúncio intersticial.

abstract Unit
show(activity: Activity)

Mostra o anúncio intersticial.

Construtores públicos

InterstitialAd

InterstitialAd()

Funções públicas

getAdUnitId

abstract fun getAdUnitId(): String

Retorna o ID do bloco de anúncios.

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

Recebe o FullScreenContentCallback para este InterstitialAd.

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

Recebe o OnPaidEventListener para este InterstitialAd.

getPlacementId

abstract fun getPlacementId(): Long

Retorna o ID da posição para este InterstitialAd.

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

Retorna o objeto ResponseInfo do anúncio carregado. Retorna null até que o anúncio seja carregado.

isAdAvailable

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

Retorna true se houver um anúncio intersticial disponível carregado de startPreload.

autoinfligida

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

Carrega um InterstitialAd.

Parâmetros
context: Context

Um contexto de atividade ou aplicativo.

adUnitId: String

O ID do bloco de anúncios.

adRequest: AdRequest

Uma solicitação de anúncio com informações de segmentação.

loadCallback: InterstitialAdLoadCallback

Um callback a ser invocado quando um anúncio intersticial terminar de carregar.

pollAd

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

Recupera o próximo anúncio intersticial carregado de startPreload ou null se nenhum anúncio estiver disponível.

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

Registra um callback a ser invocado quando os anúncios mostram e dispensam conteúdo em tela cheia.

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

Define uma flag que controla se esse objeto intersticial será exibido no modo imersivo. Chame esse método antes de show. Durante o show, se essa flag estiver ativada e o modo imersivo for compatível, SYSTEM_UI_FLAG_IMMERSIVE_STICKY &SYSTEM_UI_FLAG_HIDE_NAVIGATION serão ativados para o anúncio intersticial.

setOnPaidEventListener

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

Registra um callback para ser invocado quando se estima que o anúncio gerou receita.

setPlacementId

abstract fun setPlacementId(placementId: Long): Unit

Define um ID de posição para o anúncio intersticial.

Para garantir que esse ID de posição seja incluído nos relatórios, chame esse método antes de mostrar o anúncio.

Parâmetros
placementId: Long

Um número inteiro longo fornecido pela interface da AdMob para o posicionamento configurado.

mostrar

abstract fun show(activity: Activity): Unit

Mostra o anúncio intersticial.

Parâmetros
activity: Activity

Um contexto Activity de onde apresentar o anúncio.