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 na pausa entre os níveis de um jogo. Quando um anúncio intersticial aparece no app, o usuário pode tocar nele e acessar a página de destino ou fechá-lo e voltar ao app.
Neste guia, explicamos como integrar anúncios intersticiais a um app Android.
Pré-requisitos
Carregar um anúncio
Para carregar um anúncio intersticial, chame o método estático load() do AdManagerInterstitialAd e transmita um AdManagerInterstitialAdLoadCallback para receber o anúncio carregado ou possíveis erros. O AdManagerInterstitialAdLoadCallback usa LoadAdError para fornecer detalhes do erro.
Java
AdManagerInterstitialAd.load(
this,
AD_UNIT_ID,
new AdManagerAdRequest.Builder().build(),
new AdManagerInterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull AdManagerInterstitialAd 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
AdManagerInterstitialAd.load(
this,
AD_UNIT_ID,
AdManagerAdRequest.Builder().build(),
object : AdManagerInterstitialAdLoadCallback() {
override fun onAdLoaded(interstitialAd: AdManagerInterstitialAd) {
Log.d(TAG, "Ad was loaded.")
this@MyActivity.interstitialAd = interstitialAd
}
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 um intersticial, 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)
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:
/21775744923/example/interstitial
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.
Exemplos no GitHub
Próximas etapas
- Saiba mais sobre a segmentação de anúncios.
- Saiba mais sobre a privacidade do usuário.
- Confira a inicialização otimizada do SDK e o carregamento de anúncios (Beta).