Monetizing Your Android Mobile App using Ads

There has been a lot written about how to monetize your mobile app, and you can read some about it in one of our future posts. For this post we are going to explore adding Ads to your app to drive monetization.

We will focus on Android for this post, to start with we will need to download the Google Play services

The AdMob API currently support banner and interstitial ads, and one of the first decisions you will need to make is determine which of the ad formats work best for your application.  You could also use both together if you feel that works for your application.

The key to using ads is to make them as unobtrusive as possible, ad supported applications are becoming more of the norm these days as most consumers drift towards free services.

Interstitial ads are rendered full screen taking over the whole display area of the application, once visible they give the user the opportunity to dismiss the add or to redirect to the advertised product page. These types of ads are generally better suited for games and applications that transition between different pages on a regular basis.

Banner ads, only occupy a designated portion of the screen, they therefore stay visible for much longer periods, while not interfering with the users experience. These types of ads are well suited for single page applications like maps or document readers.

Before we begin I am going to assume that you have already gone over to the AdMob site and sign up for  an account.  If not now is a good time to do so,  you will need your unique ad unit id’s to complete this tutorial.

Configuring dependencies

We will start by adding the Google Play Services to our modules dependencies list in Android Studio.

1) Right click on your app module and select Open Module Settings

Open Module Settings

2) Select the Dependencies Tab  and Click the + button and select 1 Library Dependencies

Module Dependancies

3) Find the com.google.android.gms:play-services-ads and click Ok  and click Ok again to close the Module Settings Page

Google Services

With our module dependencies in place we can not start making the necessary changes to the code.

Adding a Interstitial Ad to your application

Incorporating interstitial ads in your application requires the following steps:

1) Add an interstitial variable in the main application page by adding the following code to our MainActivity.java file.

CropperCapture[4]

2) Instantiate our  InterstitialAd class and set the Ad Unit ID by adding the code below

CropperCapture[61]

3) Request and load the ad, by adding the following code.

CropperCapture[62]

4) Now setup a listener for to receive the onAdLoaded event, like we did below

CropperCapture[11]

5) Lastly we want to add a new method to the MainView class to show our Ad

CropperCapture[12]

If you build your application now and run it on your emulator you should see the below screen after a few seconds when the application starts.

device-2016-02-04-230846

 

Congratulations you have successfully added an interstitial Ad to your application, you can now customize how often this ad displays by going to your AdMob account.

Adding a Banner Ad to your application

Incorporating a banner ad into your application requires the following steps:

1) Create a new layout item for your banner, I chose to add this above the list in the chat_list.xml layout file.

CropperCapture[13]

 

2) In the ChatList.java within the OnCreateView method, get a reference to the AdView component that we previously added to the chat_list.xml layout file.

CropperCapture[21]

3) Create a new AdRequest object and load the new request into the AdView component

CropperCapture[31]

If you build your application now and run it on your emulator, and navigate to the chat list page you will notice the banner ad on top of the list as seen in the below capture.

CropperCapture[41]

 

Once again congratulations if you have been following along, you have now successfully added a banner ad to your mobile application.

 References

1) https://developers.google.com/admob

2) https://support.google.com/admob/answer/2773509

 

 

BY : Johan Van Zilj | CATEGORY : App Design |CATEGORY SLUG: app-design | Date : 9 February, 2016 | Tags : ,