Adding Google AdMob to an Android application

26 May, 2020 Root No Comments

AdMob is Google’s advertising platform specifically designed for mobile applications. AdMob allows you to monetize your apps by serving ads selected according to criteria you define. So if you’ve developed an Android app and now you want to make money with your app, in this article I show you how to do it, how to add different ad formats to your apps.

To get started, make sure you have integrated Firebase into your project. If you haven’t already done so, here’s how to do it.

Set up your application in your AdMob account

  1. To get started you need to create an AdMob account or sign in if you already have one.
  2. Login to AdMob and open your dashboard. Now, go to Applications> Add an Application> Fill out the information required by AdMob> Click Add, which will generate an AdMob ID for your application.
  3. To link your newly added application to Firebase. Select the application, access the application settings and under Application Information you will see an option to link the application to Firebase.
  4. Add your AdMob Application ID to your AndroidManifest.xml file by adding the <meta-data>tag.

5. Add and initialize the Mobile Ads SDK. Add the dependency of the Google Mobile Ads SDK to the build.gradle module file

You must initialize the Mobile Ads SDK, before you can broadcast any type of announcement made in one of your activities at the start of your application. Call this method only once and as soon as possible, ideally at the launch of the application.

Choose an ad format to implement in your application

AdMob offers different ad formats (Banner, Interstitial and Rewarded). You can choose the format that best suits your application’s user experience.

Banner ads take up space in the layout of an application, at the top or bottom of the device screen. They remain on the screen while users interact with the application and may refresh automatically after a period of time. To add a banner ad to one of your activities / fragments, you will need to use AdView . In your layout file, add the following code:

There are two settings to note here adSize which defines the size of your banner, there are different sizes of banners available that need to be viewed and adUnitId is the unique ID that identifies your unique ad block.

  • Loading an ad

The ad loading is done with the method loadAd() of AdViewclass. it take as parameter a object ot typeAdRequest, which contains execution information (such as targeting information) on a single ad request.

Adding Google AdMob to an Android application

Adding Google AdMob to an Android application

Interstitial announcements are full screen announcements that cover the interface of their host application. When creating interstitial advertisements, we do not need to define a view in your layout file, they can only be created by programming.

Interstitial announcements are requested and displayed by InterstitialAd objects. Start by instantiating InterstitialAd to set its announcement block ID. This is done in the onCreate() method of an activity.

  • Loading ad

To load an interstitial announcement, call the method loadAd() ofInterstitialA object, this method accept a object to typeAdRequest as unique parameter

  • Showing the Ad

To display an interstitial, use the method isLoaded() to check that the loading is complete, then call show().

Adding Google AdMob to an Android application

Adding Google AdMob to an Android application

Rewarded Video Ads are full screen video ads that users have the ability to watch in full in exchange for rewards built into the application.

Get theRewardedVideoA. object by using this method MobileAds.getRewardedVideoAdInstance().

To be notified of award-winning video lifecycle events, you must implement the RewardedVideoAdListenerclass, The award-winning announcement earpiece is defined using the method setRewardedVideoAdListener().

  • Request an award-winning video ad
  • Post an award-winning video ad

The isLoaded() method indicates whether the award-winning video ad request has been successfully processed.

Adding Google AdMob to an Android application

Adding Google AdMob to an Android application

Don’t hesitate to ask questions if you can’t understand a concept explained in the article, you can find the complete source code by clicking here.

For testing purposes, you can use the sample AdMob Application ID provided by Google:

Get started with AdMob in your Android project | Firebase

This quickstart guide is for publishers and developers who want to use AdMob to monetize an app that’s built with…

firebase.google.com

Add Firebase to your Android project

Install or update Android Studio to its latest version. Make sure that your project meets these requirements: Targets…

firebase.google.com

Fonctionnement d’AdMob

AdMob est une plate-forme Google qui vous permet de monétiser vos applications en y diffusant des annonces…

support.google.com

Facebook comments