Start a Project

Add AdMob in your Android application

AdMob by Google is an advertising platform designed for mobile app developers. It helps you to monetize your app and start earning from it by displaying ads from Google in their apps. It is the top choice for the developers because it is easy and free to implement, does most of the work by itself and you can start earning without any complex coding. It is fully customizable, you can select where to show ads and what type of ads to be displayed.

To get started with AdMob, you need a Google account which will be used to login to AdMob console. You need to add your app and then create some ad units which you will be using in your app. Creating Ad Units is easy. All you need to do is follow the instructions provided by Google but in this blog, we will be focusing on how to implement them in your Android application.

You can fully control the ads that will be displayed in your application. And for that, you can go to AdMob console and select your app. Then select “Blocking Controls” which will show the list of all the types of ads that can be displayed in your app. You can use the switch provided to disable the ads you don’t want.

Below is the screenshot of the AdMob console where you can block the particular ads.

 

 

Let us learn how to add and initialize AdMob in your app.

1) You need to add the ads dependency in your module level build.gradle.

2) You need to initialize Mobile Ads. This can be done in your Application class or you can do this anytime before creating an ad but only once.

3) In case you are using test ads which you should while developing the app. You need to register your device to show test apps. Otherwise, your apps will be not be displayed. Below provided code segment helps you to do this.

If you want to find out your test device id then check the logcat output for a message that looks like this:

 

Now we are ready to get the ads in our app and start earning. Let us now look at various types of ads provide by Google and how to implement them.

1) Banner Ads: They are rectangular image or text ads that stay on the app layout while the user interacts with the app and refresh automatically. These can be implemented in two ways.

i) Directly in XML means you can add the AdView in your XML and pass the adSize and adUnitId in the attributes and it will automatically load the ad for you.

ii) You can also add the banner type ad programmatically.

In both the cases, you would have to pass the adSize and adUnitId without them the ads will not appear.

Below is the screenshot of the Banner Ads.

2) Interstitial Ads: These are the full page ads which cover the full screen of the app. They are displayed at certain points in the application like between a transition. To implement it, we need to declare an object of the InterstitialAd class.

In the above code segment, we have created an object of the InterstitialAd class and initialized it. We have also added a listener which will show the ad as soon as it gets completely loaded. It is a good practice to load the ad a little earlier to avoid loading delay and just call the show().

Below is the screenshot of the Interstitial Ads.

3) Rewarded Video Ads: Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards. To implement these type of ads, you need to implement the RewardedVideoAdListener interface and then create an object of RewardedVideoAd class.

this will initialize your video ad and you need to call the show() function to show the ad.

When you implement the RewardedVideoAdListener interface then you will have to override its functions which will be executed according to situations like whether the user have completely watched the ad or not. the overridden methods will look like this.

Below is the video of the Rewarded Video Ads.

You can do whatever you want according to your need.

That’s all for this blog. We have Native Ads Express too but they are deprecated now and Native Ads Advanced is currently in a limited beta release. You can always check googles documentation of AdMob for more information.

Thank you very much. This is Vedesh Kumar signing off.

Exit mobile version