Tuesday, May 13, 2014

How to add advertisement (monetize) to your mobile app in android

Hi there!

today i'm gonna show, how to embed advertisements (AdMob) in your android application. I found the tutorials on the internet not so intuitive and that's the reason i'm sharing this with you. It is very streight forward if you know how... ;)

In my case, the end product was a very simple application with a single banner advertisement on the middle of the screen. It is up to you where to place it. My end result is a street narrator. It speaks to you loud the name of the streets you drive thru. This way you can concentrate on transit, if you are looking for a specific address. It is awesome if you are a courier or driving in a foreign country. It speaks 6 diffent languages. It also alerts you if you are driving to fast. Specially in countries with bad signalization it is wonderful. Search for Road Narrator on Google Play Store if you want to test it. Here is a screen shot of it:

 

Important: Bevor you start with this post, make sure you have a valid AdMob account and valid AdSense and AdWord Accounts on Google. Otherwise at the end of this post you'll not be able to test it. (without it, you'll not be able to generate your AdMod advertisement key)

Step 1:

if you don't have it already, please make sure you have downloaded the google play services like shown in the picture bellow:

Step 2:

Import the downloaded google play service lib as shown. Locate your android sdk and look for the extra folder. In there it will be the  google_play_service_lib.



Step 3:

Right click on your project > properties > Android > select the new available, imported google_play_services_lib by pressing add as shown:


Step 4:

In your project manifest make sure you have defined the followed entries:

Step 5:

In your activity_main.xml layout define (anywhere you want and need) a linearlayout like this:

Step 6:

On the top of your MainActivity define those private variables. Please NOTE, that the MY_AD_UNIT_ID is a ID you'll get as soon as you have your AdMob account. The id bellow is a fake one. (you don't want my ID right? ;)

Step 7:

At the end of your onCreate() method of MainActivity.java call the method createAdView() like definition bellow: (create it in your own) 



Then make sure you have the following entries in the methods onPause, onDestroy and onResume:

That's all! You should now be able to run it and if you are connected with the internet, you will see your first advertisement banner on the screen in the place you've defined.

Hope you like it. ;) 

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†