googleads
How To Integrate Google AdMob In Android - Mobile Advertising
preloder
Android Mobile App Development Technical Tips & Tricks

Mobile Advertising – Learn To Integrate Google AdMob In Android

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’


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.

2. Select the app status, it’s published or not.

3. Enter the app information and platform

4. Configure the app unit setting

5. Now you can see the successfully configured app ID of app unit.

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.

 

 

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

 

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.

 

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,

 

 

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

 

 

Now you can see the success screen of Test Ad.

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!

Like What You're Reading ?

The following two tabs change content below.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call