let’s make something together

Give us a call or drop by anytime, we endeavour to answer all enquiries within 24 hours on business days.

Find us

PO Box 16122 Collins Street West
Victoria 8007 Australia

Email us


Phone support

Phone: + (066) 0760 0260
+ (057) 0760 0560

, , ,

Mobile Advertising – Learn To Integrate Google AdMob In Android

  • By Sankar Raman
  • February 6, 2019

Google AdMob is the effective & most popular mobile advertising platform that let’s developers to monetize their android. iOS apps with variety type of ad format. It is very useful particularly when you are publishing a free app and want to create revenue through the ad impressions. Alongside, Integrating AdMob is such an easy task that it”s just takes few minutes to integrate it in app.

Types Of Ad’s In AdMob


Banner Ad
As name implies, Banner ads can be every effective to promote your business in a single shot and smart banners are best choice if you’re aiming to fit the ad into multiple screen sizes of the devices.


Interstitial Ad
Interstitial ads occupies full screen of the app. Basically they will shown on a timely basis, basically it’s used in Gaming apps.


Rewarded Video Ad
It’s a fullscreen Video Ads that offers reward points when user watches the ad video.


Native Ad
This type help us with flexibility to design & configure the look of an ad to resemble as if its the native ad of the app.


Now, let’s see how we can integrate it in Android apps.


Import The Ads SDK

Follow the below step to import Ads SDK,

Add The Dependency Mobile Ads SDK

You can add your dependency mobile ads SDK to your build.gradle file and here is the below implementation sdk.
Implementation ‘com.google.firebase:firebase-ads:17.1.2’

Admob dependency

How To Setup Your App In AdMob

Before everything, we need to initialize the Mobile Ads SDK and you can create your AdMob APP ID using following method.
1. Go to apps.admob.com and sign in using your Google account that is connected with your active AdSense account.
Google Admob Intergration
2. Select the app status, it’s published or not.
Google Admob Intergration
3. Enter the app information and platform
Google Admob Intergration
4. Configure the app unit setting
Google Admob Intergration
5. Now you can see the successfully configured app ID of app unit.
Google Admob Intergration

Growth Hacks: How We Improved Our Team’s Productivity By Automating Things

Configure Google Play Services In Android Studio

Step1: Open build.gradle file from Android studio and add play services dependency as AdMob requires it.
Step2: Add this SDK implementation ‘com.google.android.gms:play-services-ads:17.1.2’
Step3: Find AndroidManifest.xml file and add your AdMob App ID with in the <meta-data> tag as i mentioned below.

<!-- Sample AdMob App ID: ca-app-pub-3940256099742584~3347511715 -->


Best Read: Top 15 Productivity Tools That Help You To Save 10X More Time


Initialize AdMob SDK In “onCreate”


Step 1: Use the below code in your onCreate method to intialize AdMob SDK

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Sample AdMob app ID: ca-app-pub- 3940256099742584~3347511715
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
AdView mAdView = findViewById(R.id.adView);
         AdRequest adRequest = new AdRequest.Builder().build();

This should be done before showing any kind of ads.

Step 2: Adding Banner Ad

We can load the ads in any activity/fragment file, have to use Adview in layout.xml and add the following code in it.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

Here you can see the adUnitId and adSize. AdUnitId used to identify your single ad unit. It’s necessary to use test ID when you’re developing/testing an app and you can use your real ID when you’re using production environment. Because, AdMob policies don’t allow developer to click on the own live ads while testing. If you click your own ads multiple times then google may suspend your AdMob account ID.

Step 3: Enabling Test Ads In Android

In development, you can protect your account using test ads . For that, you need to provide your testing device id, here I have added my device id like addTestDevice(“CF15C925D76D558BF8863B09EA03E139 “) and if you are testing an app on emulator then you can use this add.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).

Step 4: Enable Your Device Id In onCreate

You can get your testing device ID from logcat and paste the complete code in onCreate as shown below,

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


Step 5: Listening Ad Events With AdListener

Ad listeners events are very useful to analyse every action that are triggered in ad’s and also to perform the very next action when ad’s are closed/ opened in an application.
Below are the ad listeners which you can use it to notify your app when ad changes its state or any action triggered.

Step 6: Add The Following Code Into MainActivity.java In Android


mAdView.setAdListener(new AdListener() {
   public void onAdLoaded() {
   public void onAdClosed() {
   public void onAdFailedToLoad(int errorCode) {
   public void onAdLeftApplication() {
   public void onAdOpened() {

Now you can see the success screen of Test Ad.
Admob Integration
All set!!! We have done with integrating Google ADMob in Android. Hope you can start doing your mobile advertising henceforth. Likewise you can do it for iOS also. Let us know your comments & queries below. We love to hear from you!
[contact-form-7 404 "Not Found"]


Sankar Raman

A full stack Android app developer having 4 years of experience in Mobile app development. Well amalgamated Co-worker who rapidly commutes in developing, implementing and adopting new technologies to wider possibilities of App development.