Intersticial recompensado (beta)

Selecciona la plataforma: Android iOS Unity Flutter

El anuncio intersticial recompensado es un tipo de formato de anuncio incentivado que te permite ofrecer recompensas por los anuncios que aparecen automáticamente durante las transiciones naturales de la aplicación. A diferencia de los anuncios recompensados, los usuarios no tienen que habilitar la vista de un anuncio intersticial recompensado.

Requisitos previos

  • SDK de anuncios de Google para dispositivos móviles 19.2.0 o una versión posterior

Implementación

Estos son los pasos principales para integrar anuncios intersticiales recompensados:

  • Carga un anuncio
  • Registra devoluciones de llamada de eventos de pantalla completa
  • Cómo controlar la devolución de llamada de recompensa
  • Muestra el anuncio

Carga un anuncio

Para cargar un anuncio, puedes utilizar el método estático load() en la clase RewardedInterstitialAd. El método de carga requiere un Context, tu ID de unidad de anuncios, un objeto AdManagerAdRequest y un RewardedInterstitialAdLoadCallback para recibir notificaciones cuando la carga de anuncios falla o se realiza correctamente. El objeto RewardedInterstitialAd cargado se proporciona como un parámetro en la devolución de llamada onRewardedInterstitialAdLoaded().

En el siguiente ejemplo, se muestra cómo cargar un RewardedInterstitialAd en tu MainActivity.

Java

RewardedInterstitialAd.load(
    MainActivity.this,
    "AD_UNIT_ID",
    new AdManagerAdRequest.Builder().build(),
    new RewardedInterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(RewardedInterstitialAd ad) {
        Log.d(TAG, "onAdLoaded");
        rewardedInterstitialAd = ad;
      }

      @Override
      public void onAdFailedToLoad(LoadAdError loadAdError) {
        Log.d(TAG, "onAdFailedToLoad: " + loadAdError.getMessage());
        rewardedInterstitialAd = null;
      }
    });

Kotlin

RewardedInterstitialAd.load(
  this,
  "AD_UNIT_ID",
  AdManagerAdRequest.Builder().build(),
  object : RewardedInterstitialAdLoadCallback() {
    override fun onAdLoaded(rewardedAd: RewardedInterstitialAd) {
      Log.d(TAG, "Ad was loaded.")
      rewardedInterstitialAd = rewardedAd
    }

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

Reemplaza AD_UNIT_ID por el ID de tu bloque de anuncios.

Regístrate para recibir devoluciones de llamada

Para recibir notificaciones de eventos de presentación, debes pasar un objeto FullScreenContentCallback al método setter de tu anuncio. El objeto FullScreenContentCallback controla las devoluciones de llamada para cuando el anuncio se presenta correctamente o no, y cuando se descarta. En el siguiente código, se muestra cómo establecer un objeto FullScreenContentCallback anónimo dentro de tu RewardedInterstitialAdLoadCallback:

Java

    rewardedInterstitialAd.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.
            rewardedInterstitialAd = null;
            if (googleMobileAdsConsentManager.canRequestAds()) {
              loadRewardedInterstitialAd();
            }
          }

          @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.
            rewardedInterstitialAd = 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.");
          }
        });

    rewardedInterstitialAd.show(
        MainActivity.this,
        new OnUserEarnedRewardListener() {
          @Override
          public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
            Log.d(TAG, "The user earned the reward.");
            // Handle the reward.
            int rewardAmount = rewardItem.getAmount();
            String rewardType = rewardItem.getType();
          }
        });
  }

  private void initializeMobileAdsSdk() {
    if (isMobileAdsInitializeCalled.getAndSet(true)) {
      return;
    }

    // Set your test devices.
    MobileAds.setRequestConfiguration(
        new RequestConfiguration.Builder()
            .setTestDeviceIds(Arrays.asList(TEST_DEVICE_HASHED_ID))
            .build());

    new Thread(
            () -> {
              // Initialize the Google Mobile Ads SDK on a background thread.
              MobileAds.initialize(this, initializationStatus -> {});

              // Load an ad on the main thread.
              runOnUiThread(() -> loadRewardedInterstitialAd());
            })
        .start();
  }
}

Kotlin

rewardedInterstitialAd?.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.
      rewardedInterstitialAd = 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.
      rewardedInterstitialAd = 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 an ad is clicked.
      Log.d(TAG, "Ad was clicked.")
    }
  }

Muestra el anuncio

Cuando muestras un anuncio intersticial recompensado, usas un objeto OnUserEarnedRewardListener para controlar los eventos de recompensa.

Java

rewardedInterstitialAd.show(
    MainActivity.this,
    new OnUserEarnedRewardListener() {
      @Override
      public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
        Log.d(TAG, "The user earned the reward.");
        // Handle the reward.
        int rewardAmount = rewardItem.getAmount();
        String rewardType = rewardItem.getType();
      }
    });

Kotlin

rewardedInterstitialAd?.show(this) { rewardItem ->
  Log.d(TAG, "User earned the reward.")
  // Handle the reward.
  val rewardAmount = rewardItem.amount
  val rewardType = rewardItem.type
}

Ejemplos en GitHub

  • Ejemplo de anuncios intersticiales recompensados: Java | Kotlin

Próximos pasos

Explora los siguientes temas: