Anúncios intersticiais

Os anúncios intersticiais ocupam toda a tela e cobrem a interface do app host. Geralmente, eles aparecem em momentos de transição natural no fluxo de um app, como entre atividades ou durante a pausa entre os níveis de um jogo. Quando um app mostra um anúncio intersticial, o usuário pode tocar nele e continuar até o destino ou fechá-lo e voltar para o app. Leia um dos nossos estudos de caso.

Neste guia, explicamos como integrar anúncios intersticiais a um app Android.

Pré-requisitos

Sempre usar anúncios de teste

Ao criar e testar seus apps, use anúncios de teste em vez de anúncios de produção ativos. Caso contrário, sua conta poderá ser suspensa.

A maneira mais fácil de carregar anúncios de teste é usar nosso ID de bloco de anúncios de teste dedicado para intersticiais do Android:

ca-app-pub-3940256099942544/1033173712

Ele foi configurado especialmente para retornar anúncios de teste em todas as solicitações, e você pode usá-lo nos seus próprios apps durante a programação, os testes e a depuração. Substitua pelo ID do seu bloco de anúncios antes de publicar o aplicativo.

Para detalhes sobre os anúncios de teste do Google Mobile Ads SDK (Legacy), consulte Ativar anúncios de teste.

Carregar um anúncio

Para carregar um anúncio intersticial, chame o método estático load() do InterstitialAd e transmita um InterstitialAdLoadCallback para receber o anúncio carregado ou possíveis erros. Assim como outros callbacks de carregamento de formato, InterstitialAdLoadCallback usa LoadAdError para fornecer detalhes do erro com maior fidelidade.

Java

InterstitialAd.load(
    this,
    AD_UNIT_ID,
    new AdRequest.Builder().build(),
    new InterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
        Log.d(TAG, "Ad was loaded.");
        MyActivity.this.interstitialAd = interstitialAd;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
        Log.d(TAG, loadAdError.getMessage());
        interstitialAd = null;
      }
    });

Kotlin

InterstitialAd.load(
  this,
  AD_UNIT_ID,
  AdRequest.Builder().build(),
  object : InterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: InterstitialAd) {
      Log.d(TAG, "Ad was loaded.")
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      Log.d(TAG, adError.message)
      interstitialAd = null
    }
  },
)

Definir o FullScreenContentCallback

O FullScreenContentCallback processa eventos relacionados à exibição do seu InterstitialAd. Antes de mostrar InterstitialAd, defina o callback:

Java

interstitialAd.setFullScreenContentCallback(
    new FullScreenContentCallback() {
      @Override
      public void onAdDismissedFullScreenContent() {
        // Called when fullscreen content is dismissed.
        Log.d(TAG, "The ad was dismissed.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdFailedToShowFullScreenContent(AdError adError) {
        // Called when fullscreen content failed to show.
        Log.d(TAG, "The ad failed to show.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdShowedFullScreenContent() {
        // Called when fullscreen content is shown.
        Log.d(TAG, "The ad was shown.");
      }

      @Override
      public void onAdImpression() {
        // Called when an impression is recorded for an ad.
        Log.d(TAG, "The ad recorded an impression.");
      }

      @Override
      public void onAdClicked() {
        // Called when ad is clicked.
        Log.d(TAG, "The ad was clicked.");
      }
    });

Kotlin

interstitialAd?.fullScreenContentCallback =
  object : FullScreenContentCallback() {
    override fun onAdDismissedFullScreenContent() {
      // Called when fullscreen content is dismissed.
      Log.d(TAG, "Ad was dismissed.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdFailedToShowFullScreenContent(adError: AdError) {
      // Called when fullscreen content failed to show.
      Log.d(TAG, "Ad failed to show.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdShowedFullScreenContent() {
      // Called when fullscreen content is shown.
      Log.d(TAG, "Ad showed fullscreen content.")
    }

    override fun onAdImpression() {
      // Called when an impression is recorded for an ad.
      Log.d(TAG, "Ad recorded an impression.")
    }

    override fun onAdClicked() {
      // Called when ad is clicked.
      Log.d(TAG, "Ad was clicked.")
    }
  }

Veicular o anúncio

Os anúncios intersticiais devem ser exibidos durante pausas naturais no fluxo de um app (por exemplo, entre as fases de um jogo ou depois que o usuário conclui uma tarefa). Para mostrar anúncios desse tipo, use o método show().

Java

if (interstitialAd != null) {
  interstitialAd.show(this);
} else {
  Log.d(TAG, "The interstitial ad is still loading.");
}

Kotlin

interstitialAd?.show(this)

Código-fonte

Exemplos no GitHub

  • Exemplo de anúncios intersticiais: Java | Kotlin

Histórias de sucesso

Próximas etapas