AdMob is a multi platform mobile ad network that allows you to monetize your android app. By integrating AdMob you can start earning right away. It is very useful particularly when you are publishing a free app and want to earn some money from it.

Integrating AdMob is such an easy task that it takes not more than 5mins. In this article we’ll build a simple app with two screen to show the different types of ads that AdMob supports.


1. Type of AdMob Ads

AdMob currently offers below types of ad units. You can choose the ad format depending on your app criteria.

> Banner Ad
Banner Ads occupies only portion of the screen depending on the ad size that is created. It comes in multiple sizes Standard, Medium, Large, Full-Size, Leaderboard and Smart Banner. Smart banners are very useful when you target multiple device sizes and fit the same ad depending on the screen size.

> Interstitial Ad
Interstitial ads occupies full screen of the app. Basically they will shown on a timely basis, between screen transition or when the user is done with a task. Usually we can see these ads in games displaying Ad when a level is completed.

> Rewarded Video Ad
Rewarded Video Ads are fullscreen video ads which offers some reward points if the user watches the ad video. These ads are very useful to offer some reward points / coins in video games.

> Native Ad
Native Ads offers flexibility to configure the ad appearance like color, text color and buttons to make them appear as native component of the app.

> Native Express (Deprecated)
Starting March 1, 2018 the Native Express ads will be discontinued.

> Native Advanced (Beta)
Native Advanced ads are still in Beta program and not available to everyone. This article will be updated once the feature is available publicly.


2. Creating Ad Units

Note: AdMob admin interface changes quite often. The below steps to create Ad Unit IDs might differ time to time.

1. Sign into your AdMob account.

2. Create a new App by giving the package name of the app you want to integrate AdMob. Once the App is created, you can find the APP ID on the dashboard which looks like ca-app-pub-XXXXXXXXX~XXXXXXXXX.

3. Select the newly created App and click on ADD AD UNIT button to create a new ad unit.

4. Select the ad format and give the ad unit a name.

5. Once the ad unit is created, you can notice the Ad unit ID on the dashboard. An example of ad unit id look like ca-app-pub-066XXXXXXX/XXXXXXXXXXX

Create as many ad units required for your app.


3. Creating New Project

1. Create a new project in Android Studio from File ⇒ New Project. When it prompts you to select the default activity, select Empty Activity and proceed.

2. Open build.gradle and add play services dependency as AdMob requires it.

compile ‘’

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''
    compile ''

    compile ''

3. Add the App ID and Ad unit IDs to your strings.xml. Open strings.xml located under res ⇒ values and add the IDs of all the ad units.

    <string name="app_name">AdMob</string>
    <string name="title_activity_second_activiy">Interstitial</string>
    <string name="msg_welcome">Welcome to Admob. Click on the below button to launch the Interstitial ad.</string>
    <string name="btn_fullscreen_ad">Show Interstitial Ad</string>
    <string name="btn_rewarded_video">Show Rewarded Video Ad</string>

    <!-- TODO - add your ad unit Ids -->
    <!-- AdMob ad unit IDs -->
    <string name="admob_app_id">ca-app-pub-XXXXXXXX~XXXXXXXXXXX</string>
    <string name="banner_home_footer">ca-app-pub-XXXXXXXX~XXXXXXXXXXX</string>
    <string name="interstitial_full_screen">ca-app-pub-XXXXXXXX~XXXXXXXXXXX</string>
    <string name="rewarded_video">ca-app-pub-XXXXXXXX~XXXXXXXXXXX</string>

4. Create a class named and extend the class from Application. In this application class we have to globally initialize the AdMob App Id. Here we use MobileAds.initialize() method to initialize the AdMob.

(Note: App ID is different from Ad Unit ID. Place the App ID carefully)


 * Created by ravi on 25/12/17.

public class MyApplication extends Application {

    public void onCreate() {

        // initialize the AdMob app
        MobileAds.initialize(this, getString(R.string.admob_app_id));

5. Open AndroidManifest.xml and add MyApplication to <application> tag to execute the class on app launch.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""


        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

3.1 Adding Banner Ad

Banner ads occupies only a portion of the screen. I am adding a banner ad in my main activity aligning to bottom of the screen. In order to add the banner ad, you need to add element to your xml layout.


6. Open the layout file of your main activity (activity_main.xml) and add the AdView widget. I am also adding a button to launch another in which we’ll try Interstitial ad.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

        android:text="@string/msg_welcome" />

        android:text="@string/btn_fullscreen_ad" />

        android:text="@string/btn_rewarded_video" />


7. Open and modify the code as shown.

> Create an instance of AdRequest and load the ad into AdView.

> Ad the AdView life cycle methods in onResume(), onPause() and in onDestroy() methods.

package info.androidhive.admob;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    private AdView mAdView;
    private Button btnFullscreenAd, btnShowRewardedVideoAd;

    protected void onCreate(Bundle savedInstanceState) {

        btnFullscreenAd = (Button) findViewById(;
        btnShowRewardedVideoAd = (Button) findViewById(;
        btnFullscreenAd.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, InterstitialAdActivity.class));

        btnShowRewardedVideoAd.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, RewardedVideoAdActivity.class));

        // TODO - remove this if condition
        // it's for demo purpose
        if (TextUtils.isEmpty(getString(R.string.banner_home_footer))) {
            Toast.makeText(getApplicationContext(), "Please mention your Banner Ad ID in strings.xml", Toast.LENGTH_LONG).show();

        mAdView = (AdView) findViewById(;

        AdRequest adRequest = new AdRequest.Builder()
                // Check the LogCat to get your test device ID

        mAdView.setAdListener(new AdListener() {
            public void onAdLoaded() {

            public void onAdClosed() {
                Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();

            public void onAdFailedToLoad(int errorCode) {
                Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();

            public void onAdLeftApplication() {
                Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();

            public void onAdOpened() {


    public void onPause() {
        if (mAdView != null) {

    public void onResume() {
        if (mAdView != null) {

    public void onDestroy() {
        if (mAdView != null) {

Now if you run the app, you should see a banner ad at the bottom of your screen.


3.2 Adding Interstitial Ad (Fullscreen Ad)

Interstitial ads occupies full screen of the app. Adding interstitial ad doesn’t require an AdView element to be added in the xml layout. Rather we load the ad programatically from the activity. Normally these ads will be populated when user is moving between activities or moving to next level when playing a game.

We’ll test this ad by creating a second activity and popup the full screen ad when the second activity is launched.

8. Create an activity named by right clicking on package New ⇒ Activity ⇒ Empty Activity.

package info.androidhive.admob;

import android.os.Bundle;
import android.widget.Toast;


public class SecondActivity extends AppCompatActivity {

    private String TAG = SecondActivity.class.getSimpleName();
    InterstitialAd mInterstitialAd;

    protected void onCreate(Bundle savedInstanceState) {

        mInterstitialAd = new InterstitialAd(this);

        // set the ad unit ID

        AdRequest adRequest = new AdRequest.Builder()

        // Load ads into Interstitial Ads

        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {

    private void showInterstitial() {
        if (mInterstitialAd.isLoaded()) {


Now if you run the app, you can see the interstitial ad when the second activity is launched.


3.3 Adding Rewarded Video Ad

9. Create another activity named and add the below code. This is same as Interstitial but there will be a callback method onRewarded() called when there is a reward after watching the video ad completely.

import android.os.Bundle;
import android.widget.Toast;


public class RewardedVideoAdActivity extends AppCompatActivity {

    private RewardedVideoAd mRewardedVideoAd;

    protected void onCreate(Bundle savedInstanceState) {

        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {

            public void onRewarded(RewardItem rewardItem) {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewarded! currency: " + rewardItem.getType() + "  amount: " +
                        rewardItem.getAmount(), Toast.LENGTH_SHORT).show();

            public void onRewardedVideoAdLeftApplication() {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoAdLeftApplication",

            public void onRewardedVideoAdClosed() {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();

            public void onRewardedVideoAdFailedToLoad(int errorCode) {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();

            public void onRewardedVideoAdLoaded() {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();

            public void onRewardedVideoAdOpened() {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();

            public void onRewardedVideoStarted() {
                Toast.makeText(RewardedVideoAdActivity.this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();


    private void loadRewardedVideoAd() {
                new AdRequest.Builder().build());

        // showing the ad to user

    private void showRewardedVideo() {
        // make sure the ad is loaded completely before showing it
        if (mRewardedVideoAd.isLoaded()) {

    public void onResume() {

    public void onPause() {

    public void onDestroy() {

3.4 Enabling Test Ads

As per AdMob Policies you are not allowed to click on your own live ads. In order to protect your AdMob account from getting suspended, use test ads during development as you might click the ads accidentally.

When you run the project, if you monitor the LogCat, you can find a similar line Use AdRequest.Builder.addTestDevice(“C04B1BFFB0774708339BC273F8A43708”) to get test ads on this device. Copy the device id and add it to AdRequest as shown below. Note that this ID varies from device to device, By doing this, the test ads will be loaded instead of live ads.

In production you need to make sure that you removed addTestDevice() methods in order to render the live ads and start monetization.

AdRequest adRequest = new AdRequest.Builder()
                // Check the LogCat to get your test device ID

3.5 Ad View Listeners

Ad listeners are very useful to perform the next action when ad is closed. Below are the ad listeners can be used to notify your app when ad changes its state.

mAdView.setAdListener(new AdListener() {
            public void onAdLoaded() {
                Toast.makeText(getApplicationContext(), "Ad is loaded!", Toast.LENGTH_SHORT).show();

            public void onAdClosed() {
                Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();

            public void onAdFailedToLoad(int errorCode) {
                Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();

            public void onAdLeftApplication() {
                Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();

            public void onAdOpened() {
                Toast.makeText(getApplicationContext(), "Ad is opened!", Toast.LENGTH_SHORT).show();

4. Known Issues

While running the app, the Ads might not display and the below errors can be seen in LogCat.

> There was a problem getting an ad response. ErrorCode: 1
> Failed to load ad: 1
If you happen find the above errors in your LogCat, there is no need worry. The newly created Ad Units takes few hours to display the actual ad. Until then you will see these errors. The best way to resolve this problem is to wait for few hours and test the app again.

Change Log

Updated On 25th Dec, 2017 (Content Update, Latest Ad Formats)
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk:
  • Thirumaran

    plzzz xplain how to get money?????????????????????

    • Place these ads in your apps. You will get money when somebody clicks on the ad.

      • Thirumaran

        thank u so much………

        • bhavik gandhi

          Hello, I want to Implement Video Ads
          So please any other that display video ads and alternative of admob

      • Eyal Engel

        Can I put an ad of my own and get money for it? or do I need to close a deal with a real company who wants to advertise on my app?
        e.g. Can I put an ad that says: “click me”, and get money if someone clicks it (although it will do nothing special…?


        • No you can’t do that using AdMob. What you are looking for BuySellAds (It supports only web). May be you can check any providers who is doing this for android apps.

  • Thirumaran

    plzzzz give some example for android Responsive preview

  • Trey Rosius

    is it advisable to place such ads on a social network?? Just wondering

  • Renitto Jose

    Thanks Ravi . it will be helpful if you could provide video regarding registering on admob and getting real ids.

    • Its nothing complex. It takes only two steps which I shown it in the image. And all the ads are real ads. We’ll make them as test ads in the code.

      • Renitto Jose

        Thank you 🙂 . But what about things like attaching my account details / paypal account with admob (i don’t know exactly this is the right way or not)

        • All the details can be managed from AdMob admin panel. Just login once and check

          • anirban mandal


  • ahmed bik

    thank you for this explain

    I have problem with this code

    Ads: Ad is not visible. Not refreshing ad.
    Ads: Scheduling ad refresh 60000 milliseconds from now.

    what I can do ?

  • Copy right

    My Friend,
    I am inform you your post is –

    is lost of copy found in google search – check this copy content link..

    Request to remove this post copy right post.

    • Thank You, I contacted them.

      • anirban mandal

        Hello !!

        • anirban mandal


      • anirban mandal

        Hi plss dont mind if i ask you a questn Ravi Tamanda do you use a commenting 3rd party or this comment section is made by your own??? Plss let me know if your using a 3rd party..then i will also use it..thnxx in advance..

      • SelvaGanesh

        hai ravi could u teach me how to create swipeable tabs using JSON valley.

  • yo_asakura

    I think the stuff in the AndroidManifest are not necessary. They are required if you use Eclipse, but in Android Studio they are not needed. Proof:

    • Yeah, I kept the in mind about both the cases.

  • ARASHI Funsho

    Thanks for this post…… came up exactly when I needed it the most. Other posts were kinda outdated……..

  • Žilvinas

    How to insert admob ad in to listview?

    • I think it’s against AdMob policies to place it listview.

  • Abhilash

    Hi, i am displaying fragment through Activity…So, How can i place Adview in fragment.?

    if i add adview in Activity_main.xml .. its showing but not floating and clickable.

  • Gamis

    Wouu thank you for the example…. actually i begin work with Ads, but i have a question…

    I need implement a VIDEO ad.. name PRE-ROLL i search and google work with IMA:

    AdMob have the same tecnologie?

  • Ramya

    We have the same app for Android and IOS. can we use the same adUnit ID for both?

    • I don’t think you can use same Unit ID for both. When we creating the app, it is asking to select the platform (check the screenshot) where we are defining the platform.

  • great tutorial. keep sharing

  • Chirag thaker

    Hello Ravi, From many times i am folowing your tutorials and its very helpful, one problem i am suffering from 2-3 days is that OutOfMemory error in loading images. i have image automatic slider in my app. so when i start running on mobile , it throws error of outofmemoryerror in logcat . please help me to solve.

    I did not know how to set background of layout or load image from Bitmap drawable so i directly load in tag.

    for background

    Thanks in advance @ravi8x:disqus

    • Don’t keep the image directly on LinearLayout. Compress the image as much as possible before adding to project. Use to compress the image.

      Also while setting the background, set the image programatically instead of setting in xml. Use the below function to compress the image and set as background to linearlayout.

      Try the below line once

  • Nithya Sri

    can anyone help me on gradle sync failed:Gradle DSL method not found: ‘compile()’

    Consult IDE log for more details (Help | Show Log)

  • haseena shaik

    I have vertically scrollable edittext inside scrollview .
    when enter key pressed layout auto scrolling. could you please help.
    thanks in advance @ravi8x:disqus

  • shivam pandey

    Hi Ravi adMob is great, No doubt. but it is not showing any impression on slideMe market devices and not even Analytics are working there. Could you suggest me something for this context.

  • Viet Nam

    HI Thanks
    very useful
    Sorry please for me ask
    I viewed all your post on android but not view post toturial Service of android.You can write post service Android ?
    If can i very grateful you because service i see it very important in some app good.Thanks

  • Deep Shikha

    Hi Ravi,
    Hope you are doing well. I have followed you on numerous topics for learning android app development. Please advise if you also take classes or guide.

    Eagerly waiting for your advise.


    Deep Shikha

  • Hiep

    Hi Ravi,

    I enjoyed your tutorials. I hope you do a tutorial on integrating Native ads admob or facebook into RecyclerView .



  • Sami

    Hi Ravi, Im totally new to this stuff so sorry for noob questions.

    I am using Navigation-Drawer in my application(i have followed your material desing tutorials). So I have created single activity with navigation_drawer layout. I am using fragments to change main content area data whenever user chooses a menu option from navigation drawer menu.Now my problem is that I want to show admob ad on every screen and when opening the navigation drawer the ad will be under the navigation menu.

    My question is: is there any conflict or contrast with the AdMob Policies ?

  • rekian

    brother, why your web deindexed on google search? only 1 page being indexed

    • Hi rekian

      Thanks for letting me know. I am checking it right away.

  • Ramesh Bista

    Hello ravi, I have a small issue.I don’t think how logical it is. What if I wished to add only desired app from playstore. For example I just want to display facebook and twitter add randomly.How can I do that if it is possible to do?

  • Manish Butola

    Great Tutorial !

  • Rahul

    Hello Ravi bhai, great tutorial. Can you please tell me how do you created that video.Please.

    • I recored the video on my mobile and used Camtasia studio to edit the video.

      • Rahul

        Thank you Ravi bhai for your reply.

  • Parth Patel

    without publishing app…i can earn through adMob??

    • No, you can’t

    • Otman Soulimani

      you can if you did publish app in other markets

  • ARASHI Funsho

    Thanks, was able to adapt the code here to display banner and interstitial ads in fragments 😉 cheers bro

  • Amarbir Singh

    getting error while adding dependency to gradle. Error-> failed to and compile&target sdk-23, min-14. Help me on this ravi!!

    • Amigo Madiq

      download the m2 repository manually or let the Gradle sync so it would be able to add the dependancy.

  • hari

    Hai Ravi sir

    I have ad mob using ad created. in that case i have getting some blank page kindly help me how to resolved in this problem

    i have attached the link below

  • Qasim

    thanks man .
    helped alot.

  • Bojan Ursus


  • Dhaval Shingala

    thanks bro…

  • SM Mizan

    i face a problem console error :- Failed to load ad: 0
    how to solve this problem.

    • Ahmed Buchery

      I’m facing the same issue, my app is play store but with no ads.

      While in development I’ve added the .addTestDevices but on production I removed it and no one that downloaded the app sees ads.

      I have create a new ad-unit with no luck

      • FaisalHyder

        As salam o alaikum, issue is that you guys might be taking app id from app-management page on admob account, don’t take it from there take app-pub id from Monetize tab and under all apps check the ad unit you made use this id in app. hope this helps.!!

  • Syed Farrukh

    Hi Ravi …
    Thanks for the tutorial everything is working fine…. can you please guide me how to integrate Video ads in android studio and one question more how to generate video Ad id in admob …. Thank you in advance dear

    • brother as far as i know, look at the image where Ravi bhai showed admob screen shots, there is also video available, i think same method will work for image/Text and video ads in Interstitial Ad.

  • jerom

    please add Admob native ads example, these tutorials are the best, easy and simple , with good explanation

  • mohammad

    hello ravi , how can I put my own ads in a banner like that , but not by google ads, like my own ads banner’? thank you brother

    • For that you don’t need AdMob, you can just show Fragment Dialog with fullscreen ImageView in it. But why do you want to do that?

    • Chris Harris

      Did you implement that?

  • shankze

    This works great on the emulator. When I run it on my phone, I don’t see the ad. What could be the problem?

    • raghavendra

      Add this line in manifest.xml

  • Arun Joy

    can you give example of new ad feature like native

  • David Kimigho

    Nice tutorial Sir. Im a big fan of your,blog. Do you mind giving a tutorial on adding an add mob banner after 5 items in a listview or Recyclerview, something related to facebook feeds

  • Raja Mohamed

    how do get the live add eventhough i removed addTestDevice method i did not get live add why?

  • Raja Mohamed

    i got test add eventhough i removed addTestDevice method i did not get live add why?

  • Raja Mohamed

    anyone will quickly response

  • Parmesh Bhande

    only one add is showing how to display different-different adds, i mean live ads. can we manage through AdMob site which adds should be display in app ?

  • Tushar takodra

    hii ravi I am using your code to integrate adMob in my app. But it only display InterstitialAd not show the video ads. i set the only video in google admob account.

    • I guess, google decides which ad to show depending on the user.

  • Amigo Madiq

    Ravi maybe it’s late to congratulate you but you deserve that. thanks bro 🤓

  • Raj Jat

    Hi Ravi, I include your code of admob but cant load and Show Adsruntime in my app
    all procedur completed……………help

  • Sateesh Kumar Reddy Nandyala

    Hi Ravi
    I want to display interstitial ad before the activity launch. Like once ads displayed then only i want to show the my activity. If possible could you please share your inputs.

  • Viru Kumar

    Hello Ravi thanks for this its very easy code

  • Viru Kumar

    Ravi plz give me some code about “Android GPS Tracking with Google map”

  • amine dexter

    hello every body,
    it’s been 24 hours i have this problem please any one could help
    the error is : Error inflating class

    • Rishab Surana

      I wonder you are working in eclipse
      if so then i recommend you to switch to Android Studio coz i also had this problem and couldn’t find any solution for this but if you are working in Studio then there should’t be any problem if you have included the google play services in the app
      But if u get any solution to this don’t forget to share it
      Hope it helps

  • Mh Emon

    Hello Ravi,

    Banner Ad is not shown in my app. but full screen ad shown perfectly.. i am fully Follow your tutorial.. i also download your apk. bt your demo app also Unable to load banner ad.
    plz help me out..

    • Farhad Mammadli

      truncate your hosts file

      • Mh Emon

        I already solve this! Thnks..

        • Manik Mittal

          Please tell how u solve this

      • giantmalik

        how to truncate?

  • Farhad Mammadli

    hi, it is disallowed interstitial implementation, isn’t it ?

  • devansh

    Can someone create this app to show ad for me. I will provide all the details necessary.

    • Chris Harris

      where is your app?

  • Sachin Vaghela

    Hi Ravi,
    Your Code is very helpful to us. but my question is i saw some different steps to Integration Google Admob in application here the link is :
    I implement your code and its working very well but i want to know which is the right way to integration?

  • Nahidul Islam Nahid

    In my app i have a banner ad also i have given ad refresh after 120 seconds. It seems to me that the estimated earnings of this banner ad is very poor according to the number of impressions it has.
    is there any strategy to apply inside my code or in ad mob ad setting for improving my estimated earning ?
    I have attached my banner ad data for last two months….

  • Dinozor Apps

    hi when I show interstitial ad the firstly click button it is open add and open new activity, but second click inactive… it is not working. how can refresh button when start interstitial and open that button for next activity

  • Hirpara Vivek

    how to set adblock in my app

  • Swati

    Hi Ravi, your tutorials are great and very helpful. In the above banner ad code there is no initialization without which it was not showing the banner.

  • Sandeep

    Sir in 3.1 Adding Banner ad what is xml

  • Sandeep

    What is xml layout in 3.1 where to ad these codes

  • Saidur Rahman

    Hi Ravi,

    I used exactly your code for Interstitial ads. It was all working fine for long time. But today I got email like this

    ……………….Interstitial ads that load unexpectedly while a user
    is viewing the app’s content.”

    It would be great if you could let me
    know how to handle this scenario.


    Thanks A LOT!

  • Great example. Made easy! Thanks

  • Gowtham M

    very nice and simple thax lot….

  • Manik Mittal

    Hey Ravi I m unable to load banner adds what is the error with this

  • Ravinder Sharma

    Hello Ravi Bro.
    Please Tell Me Admob Advance Native Ad Implements Like App Install Ad, Content Ad Etc.
    Tell Me With Profits.

  • Jayesh Prajapati

    Thanks for this.
    But how to repeat interstitial ad after 1 minute continuously.
    Thanks in advance

    • GVIEW TV

      Just add admob.oneminute. (remaining code) . It will work perfectly

    • Amit Arora

      I have android application and I need Ad code for banner ,help me in getting Ad Code

  • Ratanak Pek

    thanks, very nice and clear

  • hamy

    thats very nice thnks alot for this great help

  • Amit Arora

    From where can I get Ad code for my application ?

  • Amit Arora

    I have android application and I need Ad code for banner adds
    Can anybody help me in getting Ad Code ?

  • Furkan Özcan

    Hi Ravi. I add interstitial ad my app. But i have a problem. My ad see only first but not see other time.

  • Ḁyan Ḡhosh

    Hi Ravi,

    Can I include a video ad and note whether the user has watched till end or cancelled before it ended ?

    Please Tell me how. Thanks in advance 🙂

  • kush

    hello..thank you for that code. In emulator code work perfect but in my device not show the add..? what can i do for this…?

  • jim

    Hii Ravi..when i add test device it works perfectly fine but after removing and even after publishing adds doen’t show up

  • Kavita Patil

    Thank you .

  • Amitraj Sharma

    Hi Ravi,
    Ad failed to load! error code: getting everytime.

    • If it is a new ad ID, it takes sometime to display.

      • Amitraj Sharma

        Probably how much time it will take.

  • Nikunj D

    Hi Ravi,
    Is there any way to put x button in top right corner in MEDIUM_RECTANGLE Banner ad to close Banner Ad?

    • Don’t manipulate google ads. Your account will get banned.

      Place the Ad in a RelativeLayout and place the close button with align top, right to parent properties.


    when i close the interstatial ad logcat shows duplicate activity

    • naresh gaur

      i think you have same name two activity pls check

      • WAQAR ALAM

        In comment section I have posted a stackoverflow question link .
        Please check if you can

        • naresh gaur

          Am not able to find error pls copy error from android studio and paste here than i can recognise what is going on

  • Yasiir KhanY’x

    You need to add insted

    compile ‘’

  • Puteri Pratiwi

    hallo sir,, how to implement native ads in recycleview android studio..,

    thanks you…

  • Riashad Sabit

    hello sir….I have done all this things…but these ads are only being shown when I am testing it on android emulator (Android Studio)…But when I am testing it on an actual device (like my phone),I can’t find these ads….So please tell me what should I do????

    • name

      it takes a few hours

  • Amit Raj

    Hello Ravi,
    Is it necessary to pay money in admob account because it’s automatically turns into beta version.And after creating banner and interstitial ad i am unable to display ad on my device.I have downloaded your apk and that is also not working.Please reply….

    • If the ad blocks are newly created it takes few hours to display them.

  • Team Work

    i follow all this step and put admob ad successfully but problem is that Ad perfect display in my mobile but on other mobile its display only 1(facebbook) ad

  • Mahantesh Gurav

    It worked for me. Nice Tutorial. I follow your all tutorials, keep it up..!

  • Manoz

    yes bro it work.

  • Ashish Tiwari

    Hi Ravi, I have to use Custom ads in an application. Is it possible to add/remove Ads dynamically form outside of Google’s Interface?

  • Poor Person

    Is it illegal if i make a app and then watch the ads MYSELF and my friends and earn money?
    i need some quick money

    • If you click or watch your own ads, your account will suspended by google very soon.

  • Shivam Bhardwaj

    Hi, is it possible to make an app for my business and set ads on it for my employees to use it in office hours, so that i can earn some extra money.

    • Yes, it can be. How big the team size would be?

      • Shivam Bhardwaj


        • Shivam Bhardwaj

          Any suggestions sir

          • Shivam Bhardwaj

            My employees will use that app in office day in office hours. So is it possible to earn some money. Team is of 72 persons

          • No, this comes under Google Adsense policy violation. Google will identify you easily and disable the AdMob / Adsense account. All the employees will be in same network/location, so finding the fraudulent clicks is very easy.

          • Shivam Bhardwaj

            Sir we are not going to click any ad, i was just thinking for the money from ad impression not by clicking it. I knew it very well that clicking ads by own is offensive but I just want our office app to display ads and in month end we will get some little money for impressions.

          • You can give it a try. Unlike AdSense, getting AdMob is very easy. So loosing an account is not an issue.

  • Alpesh Dumaniya

    I have one problem request to solve it
    when i put live apk i have shown admob ads and only in my device other device does not see any ads also

  • Muhammad Nauman

    hello Ravi I have a problem
    when I use Dummy ad uint Id admob appears dummy ads but when i put real ad unit idd no ads appears please help me out .

    • If the ad ids are new it takes 5min – 3,4 hours to display the actual ads. Also make sure you have removed the test device id.

      • Muhammad Nauman

        yes i have removed the test id and with the same ad ID on new app the ads appears

        • So is it working now?

          • Muhammad Nauman

            No its Not working Ravi

  • mohd afzal uddin

    hi my self salman im a software developer i have develop an app i need some help i want to add ads on my app and earn money soo how could i

    • That is what this article explains actually.

  • Rahul Maheshwari

    Best and unambiguous tutorial i found
    Thanks man!
    Cheers to you!!!

  • Preeti Karekar

    Hello Ravi, Can we resize the width and height of the banner ad.??? if yes then how??

    • Have you tried smart ads?

      • Preeti Karekar

        Yes, But I want the ad should occupy 30% of the screen, and it is not reflecting the changes as I want

        • You can have a view / container that occupies 30% of the screen and place the smart ad inside the container.

          • Preeti Karekar

            Typically, Smart Banners on phones have a height of 50dp in portrait and 32dp in landscape.
            Though I placed the banner ad inside a view its not increasing smart banner ad, its remaining 50dp only.

            Thank you for your reply…

          • Okay. Play with different ad types.

  • Vivek Solanki

    Thank you,, Ravi 🙂

  • savari sagaya devan s

    Hi Ravi
    with Test id i can see the ads in the test device. but i added the original unitid i’m getting error

    • savari sagaya devan s

      Thank You Ravi 🙂
      i am Getting it

  • savari sagaya devan s

    hi ravi 🙂
    admob is taking too much time to load.
    is there any way to increase the loading speed?

    • I believe that completely depends on Internet speed. Could you post your code to display the ad?

  • techken

    is there an option to add timer for displaying ads..

  • savari sagaya devan s

    Hi Ravi,
    When i was doing the admob in android apps i had not given the test device id so with this anything wrong?

    • No problem at all. Test device id is to display the test ads while developing the app, so that you don’t click on real ads and get your account banned. It’s always suggested use test device id to avoid admob account deactivation.

      • savari sagaya devan s

        Thank you Ravi

  • Rakesh

    Hi Ravi,
    I am getting error ‘problem getting an ad response. ErrorCode: 0’, ‘Failed to load ad: 0’. Trying to find the issue but couldnt get that.

    • If the Ad Unit is created newly, it takes sometime (may be few hours) to display the ad. Until then you will see this error.

      • Rakesh

        Thank you so much 🙂

  • Satyendra Singh

    sir i have tested my app it shows the correct banner but now i have released my app in googleplaystore
    but i didn’t added xml file like:-

    so the ads will appear?
    my app has 80+ downloads but ads not appeared.

  • Kunal

    Please write post on SignalR in android .

  • Aakash

    Sir it is possible to take a common AD ID for banner in all activities

  • Anshad M

    Is there any option to close the rewarded video programatically?

  • I am getting error code 0 … how to fix it bro?

    • If the Ad Unit is created newly, it takes few hours to make it live.

  • vikramsinh Zala

    Here we have to Replace ” InterstitialAdActivity ” in MainActivity by ” SecondActivity “. After that error will get cleared.
    Very Useful Video for Banner Ad and Interstitial Ad but i m not getting Reward VideoAd. So if i miss anything then please give me Guidance.

    The other one Error i have faced is about Banner size in java file(Comment it) and Banner adUnitId(Comment it). So after that it will work perfectly.

    Thank you so much for posting very useful topics Demo for all of us…

    • Are you seeing any errors in LogCat for Reward Video Ad?

  • Amar. Pilot

    I had created the ads last 2 days before and still i’m getting “Error in load,error code 0”..can you please let me know why i’m troubling with these kind of issues….

    • Not sure Amar.. the error code means other things too. Please search with proper error report.

      • joseph

        good morning i downloaded admob code from your website and if i use my ids on it the app will not open but if i remove the ids i will open what can i do to make it work

  • Chobela Kakumbi

    Hai Ravi.. How does Admob know that I have clicked on my own ad? And is removing addTestDevice() methods the only thing required to make the app live for production? Can I test live ads using other devices apart from mine?

    • Hi

      They track the clicks by IP address and other device coming from device. Removing addTestDevice() makes the ads live and you should see the live ads getting displayed. You don’t have to test the live Ads, they works well without any problem.

      My suggestion is, don’t play with live ads. I myself lost lot of Adsense / AdMob account because of this article particularly.

      • Chobela Kakumbi

        Ok Ravi, thanks.

  • Najaf Ali

    Hi Ravi is it important to add ad mob app id in our app, if dint include this in our app, and just banner and interstitial ids implemented, then it would be correct ?? what is benefit to include ad mob app id

  • DaVid Silence Kawlni

    Could not resolve

    Im still stuck here. What to do? Please help…

  • Gowtham Nimmagadda

    Hi Ravi. Do we really need the adListener in our app, if we don’t perform action on Ad clicked / opened ?

    Will adMob internally uses this adListener ?

    • It’s not compulsory to use adListener. These are useful methods if you want to take any action you can use these methods or you can ignore it.

      Ex: You can see an ad played between levels in games. That is where ad listeners will be helpful to show next level once ad is completed.

  • jay barochiya

    Hello Ravi,

    i getting error in AdSize.BANNER

    Error=> java.lang.IllegalStateException: The ad size can only be set once on AdView.

    • Akash Soni

      bro same error…just do one thing remove setsize adsize in java and remove setadid in java kep these both in xml only and ad will run smoothly no error will come

    • Malik Yousaf Muhammad PK

      you need to set adsize at once mean set adsize in xml or in java not in both files(xml,java)…. if u have set in xml then remove that from java
      like mAdview.adsize();
      remove the line from java code then check it again…

  • Rama Krishna

    That was a wonderful article Ravi.

    I want to advertise my web site and app on various apps using admob, How to do them?

  • pravin sidwadkar

    when i use default unit id it works but when i use myunit id ad not display

    • spin

      Hi Pravin thats also my Question did you got any solution??

  • Tajinder Kaur

    Who we show multiple ads on single activity ?And how we get diffrent ads id ??

  • Kinjal Sakhiya

    i got this error while integration, ad failed to load error code 3;

  • Anthony Hamilton

    I’m getting this error:
    “Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
    It will be removed at the end of 2018.”

    • In your build.gradle replace ‘compile’ with ‘implementation’.

      implementation ‘’

  • Amir Thoham
    • You are missing the adSize. Add it via xml or java code.

      • Amir Thoham

        thanks sir, it’s work

  • kishan viavi

    my admob id not work in SMART_BANNER work in BANNER

  • Muhammad Saim Hashmi

    getting error of onRewardVideoAdFailed to load. and getting int code 3. I am in test mode. I have done your code as it is. What is the possibility of my error?

  • gujarati monali

    I am getting error code 0 ..,…

  • wang Z

    hello,i am chinese. i create rewardAd two days,but it load failed. errcode =3. what should i do? thanks

  • provide ads

    Failed to load ad : 0 on my Ad id with Testing device request added???

    • Wait for few hours if the Ad unit is created newly.

      • provide ads

        I`m still waiting from last 18 Hours

        • Search for the same error. Stackoverflow has other possible solutions.

          • provide ads

            I didn`t found any answer …

    • I have use this :
      fun initAdmob()
      MobileAds.initialize(this, getString(R.string.admob_id))

      val adRequest = AdRequest.Builder()
      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) //todo remove later

  • freerecharge227

    can i use in one app with Two Different ADMOB Account?

  • Anil Kapse

    Can anyone explain this in a video, I’m dumb

  • Radhe

    @ravi8x:disqus sir, please make post on manage admob ad unit from firebase database. so user can manage it for safe adsence account or manage invalid activity in real time, and when the adsence account disable then the user can put new ad units in already uploaded apps.

  • salman arshad

    Hi… i used multiple ad units in my application it is working fine in my Mobile which is nougat but in Marshmallow mobiles ads keep loading and sometimes loaded….can u help me with this one

  • Uhs

    Can someone make a video for integration of admob…..
    I’m unable to understand….

  • Sarvjeet Saini

    i have an admob account in which i have some apps with working live ads properly, now i created a new app in android studio with admob……and also add that in admob account ….then i generate app id and the banner id . Test ads are working properly but when i try to use live ads with banner ad id from my admob account …..then it’s showing “Ad failed to load : error code 3” I know this error will come when we have newly created admob id…….everyone on internet is saying that …………but i wait from long time but still live ads are not showing . i have single admob banner with correct code but i dont know why this problem occuring……..i used this same id for iphone app and live ads are showing there…….but not working in android …………..please help me….

  • sanket

    * Google ads came with direct code
    * Facebook ads came with direct code.
    * But when i used mediation, it gives google ads only. No Facebook add is comming through Mediation. with the use of MediationTestSuite, it gives same error “Internal server error for Facebbok”.

  • Manoj Pawar


    I am trying to show admob in my application but getting error msg which is:
    I/Ads: Ad failed to load : 3

    why im getting this error msg ?

    • It should be temporary for newly created ad block.

      • Manoj Pawar

        thanks for replying me

        I have created ad unit id 1 week before, I thing it is sufficient time to activate unit id

        I am using admob account one of my another app which is working fine. i don’t understand why in my current app have issue to display ads.

        thank you so much for supporting