Android Apps

How To Add AdMob Banner and Interstitial Ads to an Android App

Add AdMob ads without getting your account banned. Test IDs, banner and interstitial code, the placement rules Google enforces, and what apps really earn.

An Android app showing an AdMob banner advert

AdMob is how most free Android apps make money. Adding it is straightforward — the SDK is a few lines and the code below works as it is.

What is not straightforward is staying inside Google's rules. An AdMob ban is permanent and there is rarely a way back, so the rules matter more than the code. Both are covered here.

Read this before you write any code

One rule, and breaking it is the most common way new developers lose their account:

Never click your own ads. Never use real ad unit IDs while testing.

Google detects invalid traffic automatically. It does not need a person to report you, and there is no appeal that usually works. Use the test IDs in this guide during development and only swap in your real IDs at release.

Google's official test IDs, safe to click as much as you like:

Ad typeTest ID
App IDca-app-pub-3940256099942544~3347511713
Bannerca-app-pub-3940256099942544/6300978111
Interstitialca-app-pub-3940256099942544/1033173712
Rewardedca-app-pub-3940256099942544/5224354917

Step 1: Create the AdMob account

  1. Sign up at admob.google.com with a Google account
  2. Apps → Add App. If the app is not published yet, choose "No, it is not listed"
  3. Note the App ID, which looks like ca-app-pub-XXXX~YYYY with a tilde
  4. Ad units → Add ad unit for each format you want. These use a slash: ca-app-pub-XXXX/YYYY

Tilde for the App ID, slash for ad units. Mixing them up causes an initialisation crash that is hard to diagnose.

Step 2: Add the SDK

In build.gradle (Module: app):

dependencies {
    implementation 'com.google.android.gms:play-services-ads:23.6.0'
}

Then Sync Now. Check the current version on the AdMob site — an old SDK eventually stops serving ads.

Manifest

In AndroidManifest.xml, inside <application>:

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

And above <application>:

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

A missing App ID in the manifest crashes the app immediately on launch. If your app dies the moment you add AdMob, check this first.

Step 3: Initialise the SDK

Once, in your launcher activity:

import com.google.android.gms.ads.MobileAds;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MobileAds.initialize(this, initializationStatus -> {});
}

Step 4: Add a banner

In your layout, at the bottom:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />

Then load it:

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

AdView adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

That is the whole banner. Run it and a test advert appears at the bottom.

Where to put a banner

At the bottom, always. A banner at the top pushes your content down and gets tapped by accident, which counts as invalid traffic. A banner in the middle of a list is against the policy outright.

Step 5: Add an interstitial

Interstitials are the full-screen ads. They pay far more than banners and annoy people far more, so timing is everything.

import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.google.android.gms.ads.LoadAdError;
import androidx.annotation.NonNull;

private InterstitialAd interstitialAd;

private void loadInterstitial() {
    AdRequest request = new AdRequest.Builder().build();
    InterstitialAd.load(this,
        "ca-app-pub-3940256099942544/1033173712",
        request,
        new InterstitialAdLoadCallback() {
            @Override
            public void onAdLoaded(@NonNull InterstitialAd ad) {
                interstitialAd = ad;
            }
            @Override
            public void onAdFailedToLoad(@NonNull LoadAdError error) {
                interstitialAd = null;
            }
        });
}

Show it:

private void showInterstitial() {
    if (interstitialAd != null) {
        interstitialAd.show(this);
        interstitialAd = null;
        loadInterstitial();   // load the next one straight away
    }
}

Load it early, show it later. An interstitial takes a few seconds to fetch. Call loadInterstitial() in onCreate() so it is ready when the moment comes. Calling load and show together means it usually is not ready and nothing appears.

When to show one

Only at a natural break:

  • Between levels in a game
  • After finishing a task, not before starting one
  • When moving between major sections

Never on app launch, never while something is loading, and never more than once every couple of minutes. Google's policy is explicit about interstitials that interrupt rather than punctuate.

Step 6: Test on a real device

Test ads appear with a "Test Ad" label. If you see that, everything is wired correctly.

Register your own device as a test device so that even real ad units serve test content on it:

import com.google.android.gms.ads.RequestConfiguration;
import java.util.Arrays;

RequestConfiguration conf = new RequestConfiguration.Builder()
        .setTestDeviceIds(Arrays.asList("YOUR_DEVICE_ID"))
        .build();
MobileAds.setRequestConfiguration(conf);

Your device ID is printed in Logcat the first time an ad loads. Search for "Use RequestConfiguration".

The rules that get apps banned

These are the ones people actually break:

  1. Clicking your own ads. Even once. Even accidentally. Use test IDs.
  2. Asking anyone to click. No "support us by tapping the ad". Instant ban.
  3. Ads near buttons. If an advert sits where a user expects a button, accidental taps follow and Google treats them as invalid.
  4. Too many ads on one screen. One banner and one interstitial is the safe limit.
  5. Ads over content. Nothing important may sit behind an advert.
  6. Ads in the wrong app. No adult content, no copyright infringement, no apps that just wrap a website with ads on top.

What you will actually earn

Honest numbers, because the guides promising thousands a month are not.

MeasureTypical range
Banner eCPM$0.20 – $1.50
Interstitial eCPM$2 – $12
Rewarded video eCPM$8 – $25

eCPM is the earning per thousand ad views. Two things drive it hard:

  • Where your users are. Traffic from the US, UK and Gulf countries pays many times more than traffic from South Asia. The same app can earn ten times more depending purely on audience.
  • How engaged they are. An app opened daily earns far more than one opened once.

A realistic picture: an app with 1,000 daily active users in a low-eCPM region earns roughly $1 to $5 a day from banners, more with well-placed interstitials. Payout starts at $100, so your first payment may take months.

Common problems

The app crashes as soon as I add AdMob

The App ID meta-data is missing from the manifest, or it is an ad unit ID instead of an App ID. The App ID has a tilde; ad units have a slash.

Ads never appear

Check Logcat for the error code. ERROR_CODE_NO_FILL means no advert was available, which is normal for brand-new accounts and in small markets. ERROR_CODE_NETWORK_ERROR means the internet permission is missing.

Test ads work, real ads do not

Completely normal for the first few days. New ad units take time to start serving, sometimes up to 48 hours. Do not keep changing things — wait.

"Ad failed to load: 3"

Error 3 is no fill. Not a bug. Your app is new, your region has low demand, or there is simply nothing to show at that moment. Always keep your layout working when no advert loads.

The interstitial does not show

It was not loaded in time. Load it in onCreate(), not at the moment you want to show it.

My account was disabled

Almost always invalid clicks — your own taps, or asking users to click. There is an appeal form, but reinstatement is uncommon. This is why test IDs matter so much.

A fair alternative

Ads are not the only option, and for a small app they are often the worst one. A one-time paid app, or a small in-app purchase to remove ads, earns more per user and keeps people happier.

The usual pattern that works: give the app away free with modest ads, and offer a cheap "remove ads" purchase. The people who dislike ads pay you; the rest still count.

Where to go next

Questions people ask

Can I click my own AdMob ads to test them?
No, never. Google detects invalid traffic automatically and an AdMob ban is usually permanent with no successful appeal. Use the official test ad unit IDs during development, which are safe to click as often as you like, and only switch to real IDs at release.
Why does my app crash right after I add AdMob?
The App ID meta-data is missing from AndroidManifest.xml, or an ad unit ID was used in its place. The App ID contains a tilde, ad unit IDs contain a slash. Mixing them up crashes the app at launch.
What does "Ad failed to load: 3" mean?
Error code 3 is no fill — no advert was available to show. It is not a bug. New accounts, new ad units and small markets all see it often. Always make sure your layout still looks right when no ad loads.
How much money can an app make with AdMob?
Banner eCPM is typically $0.20 to $1.50 per thousand views, interstitials $2 to $12, rewarded video $8 to $25. An app with 1,000 daily users in a low-eCPM region earns roughly $1 to $5 a day from banners. Audience location matters more than anything else.
Why do test ads work but real ads do not?
New ad units take time to start serving, sometimes up to 48 hours. This is normal. Do not keep changing the configuration while you wait, because that only makes it harder to tell what fixed it.
Where should I place a banner ad?
At the bottom of the screen. A banner at the top pushes content down and gets tapped by accident, which counts as invalid traffic. Placing ads inside lists or near buttons breaks AdMob policy.
When should I show an interstitial ad?
Only at a natural break: between game levels, after a task completes, or when moving between major sections. Never on launch, never during loading, and not more than once every couple of minutes.
Why is my interstitial not showing?
It was not loaded in time. Interstitials take a few seconds to fetch, so call the load method in onCreate and show the ad later. Loading and showing in the same moment almost always fails.
What gets an AdMob account banned?
Clicking your own ads, asking users to click, placing ads where buttons are expected, showing too many ads on one screen, covering content with ads, or running ads in apps that break Play Store policy.
Is AdMob the best way to make money from an app?
Not always. For a small app, a one-time purchase or a cheap remove-ads option often earns more per user and annoys fewer people. A common pattern is free with modest ads plus an inexpensive upgrade to remove them.

Written by Habib Baloch

I build Android apps, websites and Ubuntu servers, and write down exactly how I did it.

Ask me about this guide →