Download Code

Integrate Google Admob Ads Android

AdMob by Google is a mobile advertising platform that you can use to generate revenue from your app.It’s multi platform ads network like Android,IO’s etc.There are basically four types of Admob ads but two types mostly used in apps.In this tutorial you will learn how to integrate google admob ads in android.

  • Banner
  • Interstitial
  • Rewarded Interstitial
  • Native

First you will need an id of ads to integrate Google Admob ads for that purpose do the following steps.

  • Sign Up for Admob Account from Website.
  • Next go to Monetize menu option.
  • Click on Monetize new app button on left top corner.
  • Next click on Add your app manually.
  • Add app name and select platform(Android).
  • After adding app it will generate an ads id(ca-app-pub-9435637517621126~3008884495).
  • Then select ad format(Banner,Interstitial) and ad unit name.
  • At last Save and Done.

Create new android application project.Import Google Play Services Library.Go to activity_main.xml  and add  google adView.This is the code to integrate google admob ads of type BANNER.

activity_main.xml

google admob ads,Integrate Google admob,admob,google admob,banner ads admob, interstitial ads using admob,how to display ads in android, how to display ads using google admob in android, Adrequest,how to generate ads id using admob, InterstitialAd,AdView,Adrequest.Builder.build, how to test ads on device in android, how to test admob ads in android, how to find device id to test admob ads in android, loadAd,how to loadAd in android, setAdUnitId,setAfListener,google play services lib ads in android

Alright When you are testing ads don’t test real ads.Why because when you click on real ads again and again.Admob will terminate your Admob Account.

Testing Ads

AdView mAdView = (AdView) findViewById(R.id.adView);
		AdRequest adRequest = new AdRequest.Builder()
		.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
		// Check the LogCat for you test device ID
		.addTestDevice("F50F1E706F25B1DBC1816D4A5ACEDE52").build();

Test Real Ads

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

MainActivity.java

package com.example.ads;

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

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {
	// interstitial ads variables 
	private InterstitialAd interstitialAds = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// refering adView in xml 
		AdView mAdView = (AdView) findViewById(R.id.adView);
		// specifying test ads with device id or emulator
		AdRequest adRequest = new AdRequest.Builder()
		.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
		// Check the LogCat to get your test device ID
		.addTestDevice("F50F1E706F25B1DBC1816D4A5ACEDE52")
		.build();
		
		interstitialAds = new InterstitialAd(this);   // initializing interstitial ads 
		
		
		mAdView.loadAd(adRequest);    // loading banner ad
		// setting unit id for interstitial ad
		interstitialAds.setAdUnitId("ca-app-pub-9435637517621126/1348851290");
		// loading test ad using adrequest
		interstitialAds.loadAd(adRequest);
		
		interstitialAds.setAdListener(new AdListener() {

			@Override
			public void onAdLoaded() {
				// TODO Auto-generated method stub
				super.onAdLoaded();
				interstitialAds.show();  // interstitial ad
			}
			
		});
		
		
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

Android Manifest.xml

google admob ads,Integrate Google admob,admob,google admob,banner ads admob, interstitial ads using admob,how to display ads in android, how to display ads using google admob in android, Adrequest,how to generate ads id using admob, InterstitialAd,AdView,Adrequest.Builder.build, how to test ads on device in android, how to test admob ads in android, how to find device id to test admob ads in android, loadAd,how to loadAd in android, setAdUnitId,setAfListener,google play services lib ads in android

Run your android application project.

google admob ads,Integrate Google admob,admob,google admob,banner ads admob, interstitial ads using admob,how to display ads in android, how to display ads using google admob in android, Adrequest,how to generate ads id using admob, InterstitialAd,AdView,Adrequest.Builder.build, how to test ads on device in android, how to test admob ads in android, how to find device id to test admob ads in android, loadAd,how to loadAd in android, setAdUnitId,setAfListener,google play services lib ads in android

That’s it for this tutorial.

Thanks.