How To Insert AdMob Interstitial Ad In Your Android App

In this article, I will show you how to insert Interstitial Ad code in your Android Application. But before that let me give you a brief idea about what is Interstitial Ad. 

Interstitial Ad is one of the Ad types of AdMob which helps in generating revenue by displaying Ads on your App. To learn more about AdMob and Interstitial Ad click on the link provided below.

What is AdMob and how to generate Ad unit ID?

There are total four types of AdMob Ads through which you can earn money. You can click on the link below to learn more about other types of AdMob Ads.

  1.  Banner Ad
  2.  Native Ad
  3.  Rewarded Ad
  4.  Interstitial Ad

Now, let’s get started with how to place a code of Interstitial Ad in your Android Application. I have assumed that you are using Android Studio for developing your app and your project is opened in it. Follow the below steps and copy paste the code into your project carefully.

⟩⟩  First of all, you need to add below line of code in your build.gradle dependencies file.

compile 'com.google.android.gms:play-services-ads:8.4.0'

after adding the above code you will get a sync now option at the top right corner of the page. Click on that and wait for a few minutes to complete the process, once the gradle building is finished you are ready to go with the next steps.

⟩⟩ Then open the Manifest file and add Internet permission to it.

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

⟩⟩  Now open MainActivity.java and add only line number 2 & 3 in public class as shown below

public class MainActivity extends AppCompatActivity {
InterstitialAd mInterstitialAd;
private InterstitialAd interstitial;
}

⟩⟩  Now open MainActivity.java and add below lines of code in onCreate() method

    AdRequest adRequest = new AdRequest.Builder().build();
        
        // Prepare the Interstitial Ad
        interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
        interstitial.setAdUnitId(getString(R.string.admob_interstitial_id));

        interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
// Call displayInterstitial() function
                displayInterstitial();
            }
        });

⟩⟩  Then add below lines of code before the last curly bracket of MainActivity.java 

public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}

⟩⟩  Now open string.xml file in values folder and paste the below line of code.

<string name="ad_unit_id">ca-app-pub-39402560999xxxxx/21772xxxxx</string>

Interstitial AdMob ID used here is a sample ID. In order to get revenue, you need to replace this test ID with your own Interstitial Ad ID.

If you don’t know how to get your own Interstitial Ad Id then check this guide on how to get Interstitial Ad Unit ID.

Note: Don’t use your real Ad Unit ID while testing and never click on your own Ads it is against AdMob Policy.

That’s it, friends, this is the correct and simple way to insert Interstitial Ad in your Application. Just follow the above steps and copy paste the code carefully at the correct location mentioned above.

If you are a beginner you will love to learn Android Application development from scratch.

If you found this article helpful please do comment below and share the article to support me. If you have any suggestion please feel free to comment below.

4 thoughts on “How to insert AdMob Interstitial Ad in your Android App”

  1. We have find out a number of great things in this article. Surely cost bookmarking pertaining to revisiting.. admob I personally delight simply how much test you set to create this kind of fantastic informative web-site.

Comments are closed.

Hostinger Special offer

hostinger review

Get Now

We use cookies for essential website functions and to better understand how you use our site, so we can create the best possible experience for you ❤️

elegantespace logo png

How to insert AdMob Interstitial Ad in your Android App (Write Your Opinion)