Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Crear anuncio Admob Interstitial en Android

Tiempo de lectura: 2 minutos

Hoy vamos a aprender cómo podemos implementar un anuncio Interstitial en Android con Java.

Primero implementaremos en nuestro build.gradle:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
implementation 'com.google.android.gms:play-services-ads:23.0.0'
implementation 'com.google.android.gms:play-services-ads:23.0.0'
    implementation 'com.google.android.gms:play-services-ads:23.0.0'

Después tenemos que inicializar los anuncios en nuestro MainActivity:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MobileAds.initialize(
this,
new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
MobileAds.initialize( this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} });
    MobileAds.initialize(
        this,
        new OnInitializationCompleteListener() {
          @Override
          public void onInitializationComplete(InitializationStatus initializationStatus) {}
        });

Y añadimos en el manifest (debajo de </application>)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />
    <meta-data
        android:name="com.google.android.gms.ads.AD_MANAGER_APP"
        android:value="true" />

Y también dentro de <application> </application>

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="TU_ID_APLICACION_ADMOB" />
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="TU_ID_APLICACION_ADMOB" />
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="TU_ID_APLICACION_ADMOB" />

Cambia TU_ID_APLICACION_ADMOB por el id de tu APP de Admob.

Ahora vamos a crear nuestro anuncio interstitial:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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");
}
}
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"); } }
    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");
        }
    }

En la parte de

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public void onAdDismissedFullScreenContent() {
public void onAdDismissedFullScreenContent() {
  public void onAdDismissedFullScreenContent() {

//Anuncio cargado, puedes realizar la accion que quieras puedes indicar la accion que quieras realizar una vez cargado el anuncio.

Recuerda indicar tu id de anuncio aqui: InterstitialAd.load(this, «tu_id_anuncio_admob_video», adRequest,

0

Deja un comentario