#google #admob #banner #android
Admob guide app: https://play.google.com/store/apps/de...
Banner Ads [Part 3]
Learn how to earn money (monetize) from your android applications using google admob.
This video explains the implementation of Banner Ad type for android applications.
Test Ad Unit ID for Banner Ads: ca-app-pub-3940256099942544/6300978111
Source code of application: https://github.com/shaheershukur/Admo...
Closed Captioning:
Admob banner ads are simplest ads that can be set somewhere within the application screen.
Here are some examples of banner ads.
Let’s implement this in our demo application.
Let’s open the java and XML files of Banner Ads Activity.
For this demo, let the banner ad be displayed at the bottom of the screen.
Let’s design the screen accordingly.
First, we need to add the 'AdView' tag.
Inside that, add the 'xmlns:ads' statement, for setting 'adSize' and 'adUnitId'.
The attributes 'adSize' and 'adUnitId' are important and must be properly set.
There are different variants of 'adSize' for Banner Ads.
Depending on our requirement, we can select any one of these.
The 'SMART_BANNER' size will automatically fit ads to screen according to the device in which it is displayed.
For a better look, let's add a dummy backgroud image for our demo application.
The 'adUnitId' must be the ad unit id we generate from admob website.
Here is how to do that.
Open admob website.
Click on the app for which ad unit id needs to be created.
Select the 'Ad Units' section.
For now, we will create 'Banner' ad.
Just give a ad unit name of your choice. You can use this name to track earning of each ad units in you application.
Copy the Ad Unit ID you have created, and paste it in the 'adUnitId' attribute.
If we click on our own ads, the admob account will be suspended.
hence,until the application development is completed, we must use the test unit ID.
This is the test ID which must be used through out the development of application.
Now, as seen in the previous video, we must initialize the admob ad in the 'onCreate()' method.
After that, we must load the admob ad.
For that, let's create a reference to the banner Ad 'AdView' we had created in the XML file, using the 'findViewById()' method.
Create a 'AdRequest' object.
Now call the 'loadAd()' method on the banner Ad by passing adRequest to it.
Let's run the application.
As you can see, the Banner Ad is loaded and displayed in the application.
We can also carry out some tasks in the application based on the ad events.
For that, we must set a Ad Listener to the banner ad, like this.
Inside the 'setAdListener()' method, pass a new object of 'AdListener' class.
Press 'Alt' + 'Insert' keys to override methods.
You can select the methods you want to override.
Based on the requirement, we can do desired tasks when these ad events occurs in the application.