Android How to Integrate Google AdMob in your App

android-integrating-admob-banner-interstitial

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.

android-admob-creating-ad-unit

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.

implementation ‘com.google.android.gms:play-services-ads:11.8.0’

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.

4. Create a class named MyApplication.java 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)

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(“D0&DFSDSD774708339BC273F8ADG56”) 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.

Leave a Reply