How to create an ADMOB Interstitial Ad in Android Studio | Google Admob Interstitial Ad Network

In this article, we have to create an AdMob interstitial ad format that is used to implement the bottom of the layout or else the top of the layout. So, we have to implement the below code in your project and follow it step by step.

STEP: 01

We can insert dependency in your build.gradle(Module: level) given below.

// Admob Ads Dependency
implementation 'com.google.android.gms:play-services-ads:21.1.0'

STEP: 02

Insert Meta-Deta in your “manifests” file given below.

<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>

STEP: 03

We have to insert INTERNET permission to run this banner ad given below.

<uses-permission android:name="android.permission.INTERNET" />

STEP: 04

we have to create a java code to show ads under the onCreate method in your project given below.

// Interstitial Ad
loadInterstitialAd();

Now, we have created the main code under AppCompactActivity.

public void loadInterstitialAd() {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this, "ca-app-pub-3940256099942544/1033173712", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {

Toast.makeText(MainActivity.this, "Ad Loaded", Toast.LENGTH_SHORT).show();
interstitialAd.show(MainActivity.this);
interstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
super.onAdFailedToShowFullScreenContent(adError);
Toast.makeText(MainActivity.this, "Faild to show Ad", Toast.LENGTH_SHORT).show();
}

@Override
public void onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent();
Toast.makeText(MainActivity.this, "Ad Shown Successfully", Toast.LENGTH_SHORT).show();
}

@Override
public void onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent();
Toast.makeText(MainActivity.this, "Ad Dismissed / Closed", Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
Toast.makeText(MainActivity.this, "Failed to Load Ad because=" + loadAdError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}

————— THANK YOU VERY MUCH —————

Leave a Reply

Your email address will not be published. Required fields are marked *

× Chat Now