Interstitial Ads[Part 4] | Admob monetization for Android Apps | Admob tutorial

Опубликовано: 22 Сентябрь 2019
на канале: Shaheer Shukur
1,393
24

#google #admob #interstitial #android
Admob guide app: https://play.google.com/store/apps/de...
Interstitial Ads [Part 4]
Learn how to earn money (monetize) from your android applications using google admob.
This video explains the implementation of Interstitial Ad type for android applications.
Test Ad Unit ID for Interstitial Ads: ca-app-pub-3940256099942544/1033173712

Source code of application: https://github.com/shaheershukur/Admo...

Closed Captioning:
Interstitial Ads are full-screen ads that we can put up between transition points in our application.
For example, between different levels of a game.
Let's say, we are in 'Level 1'.
Now on clicking 'Next level' button, we will display an interstitial ad before taking to the next level of game.
Let's implement this in our demo application.

Open java and XML files of Interstitial Activity.
Let's create a mockup of a game.
Say, we are in 'Level 1' of game.
On clicking 'Next level' button, the app should display an interstitial ad, and continue to the next level of game.
Let's add a function to be executed on clicking the 'Next level' button.
We will name the function 'nextLevel'.
Open the java file, to write function definition.
We will access and change the 'textView' text.
Let's add an 'id' to the 'textView' and access it inside the function.
On click of the button, let's change the text from 'Game Level 1' to 'Game Level 2'.
Let's run the application.
Now, We will add an 'Interstitial ad' on clicking the 'Next level' button.

In the 'onCreate()' method, first we must initialize Admob.
Now, create an 'Interstitial Ad' variable, and assign it to an instance of 'InterstitialAd' class.
pass 'this' as the context.
Next, we must set the 'ad unit ID' to the interstitial ad object we have created, using the function 'setAdUnitId()'.
To generate the Ad Unit ID, open the admob website.
Select the 'Interstitial' Ad type.
Give a name for the Ad Unit, and click on 'Create Ad Unit'.
From here, copy the generated Ad unit ID.
Now paste it in the function parameter.
As we know, we must always use the test ad unit ID during application development and testing.
This is the test unit ID for interstitial ads.
Now, inside 'onCreate()' method itself, we will load the interstitial ad.
For that, call the function 'loadAd()' on the interstitial object.
pass the 'build()' function of 'AdRequest' class as parameter.

We want to display the Ad on clicking of the button.
Inside the 'nextLevel()' function, invoke the 'show()' method of interstitial ad object.
Also, we should make sure that the ad is displayed, only if loading of ad is completed.
For that check, we can use the 'isLoaded()' method on the interstitial ad object.

Let's run the application.
Click on 'Next Level' button.
Notice that the ad is not displayed because loading of ad is not yet completed.
We will try it once again, but after waiting for some time.
Let's click on the button now.
As you can see, the interstitial ad is displayed to the user.

We can also perform some tasks in the application depending on the admob events.
For that, set an Ad listener for the interstitial ad object, by passing an instance of 'AdListener' class as parameter.
Press 'Alt' + 'Insert' keys to override the methods.
We can override these methods.
A typical use of overriding the 'onAdClosed()' method is to reload the interstitial ad for displaying it for the next time.
We just have to call the 'loadAd()' method again inside this overrided method.
Depending on the application requirement, we can override other methods too.