Today we’re going to learn how to implement an Interstitial ad on Android using Java.

First, we’ll implement in our build.gradle:
implementation 'com.google.android.gms:play-services-ads:23.0.0'
Then, we need to initialize the ads in our MainActivity:
MobileAds.initialize( this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} });
And add in the manifest (below </application> ):
<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />
And also inside :
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="TU_ID_APLICACION_ADMOB" />
Replace YOUR_ADMOB_APP_ID with your Admob APP ID.
Now let’s create our interstitial ad:
private InterstitialAd mInterstitialAd; public void cargarAnuncioVideo() { try { AdRequest adRequest = new AdRequest.Builder().build(); InterstitialAd.load(this, "tu_id_anuncio_admob_video", adRequest, new InterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { // The mInterstitialAd reference will be null until // an ad is loaded. mInterstitialAd = interstitialAd; Log.i("TAG", "onAdLoaded"); if (mInterstitialAd != null) { mInterstitialAd.show((Activity) getApplicationContext()); } else { Log.d("TAG", "The interstitial ad wasn't ready yet."); } mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() { @Override public void onAdClicked() { // Called when a click is recorded for an ad. Log.d("TAG", "Ad was clicked."); } @Override public void onAdDismissedFullScreenContent() { // Called when ad is dismissed. //Anuncio cargado, puedes realizar la accion que quieras // Set the ad reference to null so you don't show the ad a second time. Log.d("TAG", "Ad dismissed fullscreen content."); mInterstitialAd = null; } @Override public void onAdFailedToShowFullScreenContent(AdError adError) { // Called when ad fails to show. Log.e("TAG", "Ad failed to show fullscreen content."); mInterstitialAd = null; } @Override public void onAdImpression() { // Called when an impression is recorded for an ad. Log.d("TAG", "Ad recorded an impression."); } @Override public void onAdShowedFullScreenContent() { } }); } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { // Handle the error Log.d("anuncio", loadAdError.toString()); mInterstitialAd = null; } }); } catch (Exception e) { Log.e("anuncio", "falla1"); } }
In the part of public void onAdDismissedFullScreenContent() {
* You can specify the action you want to perform once the ad is loaded.
Here: «your_admob_interstitial_ad_id» you will indicate your rewarded ad id.
