To monetize the android apps, Google provided a mobile ad network called AdMob to show the ads in applications. If we want to earn the revenue from our android apps, then the AdMob platform is the perfect solution to easily integrate the ads in our android apps.
AdMob network provides different types of ad formats, so we can choose the ads which best fit our app’s user experience. The following are the different types of ad formats available for android apps.
Banner ads are a rectangular image or text ads that occupy a spot within an app's layout. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.
Interstitial Ads are full-screen ads that cover the interface of an app until closed by the user. They're best used at natural pauses in the flow of an app's execution, such as in between levels of a game or just after completing a task.
Rewarded video ads are full-screen video ads and it rewards the users for watching the ads.
To earn the revenue by integrating the Google AdMob ads in android applications first, we need to register an account in AdMob, create ad units in AdMob and we need to integrate Google Mobile Ads SDK into an app.
To create ad units in AdMob first, we need to Create an Account in AdMob and need to register our app in the AdMob network.
Follow the below steps to register and create ad units in the AdMod network.
Once we are done with creation of Ad Unit that will show in our Dashboard like as shown below.
In case, if you want to create more ad units, just click on ADD AD UNIT button and create it based on your requirements.
Now we will see how to integrate AdMob Ad Units in our android application to show the ads with example.
To start integrating AdMob ads in our android application, we need to import the Google Mobile Ads SDK with Gradle dependency that points to Google’s Maven repository, for that open your app à Gradle Scripts à build.gradle (project) and add maven repository in allprojects section like as shown below.
Now we need to add google play services to our application, for that open your app à Gradle Scripts à build.gradle (Module: app) and add following google play services compile statement to the dependencies{} section.
...
}
The above one instructs Gradle to pull the latest version of the Mobile Ads SDK. Once you are done with adding required dependencies, save the file and perform a Gradle sync.
To load the ads in our app, we need to initialize Mobiles Ads SDK by calling MobileAds.Initialize() with our AdMob App ID.
Following is the example of calling the initialize() method in an activity.
package com.tutlane.admobexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.MobileAds;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "ca-app-pub-3214000786576152~8215460912");
}
}
We are done with importing Mobile Ads SDK and we are ready to implement and ads in our application.
Google AdMob provided a different type of ad formats (Banner, Interstitial and Rewarded), we need to choose the one that best fits our app’s user experience.
Banner ads are rectangular image or text ads that occupy a spot within an app's layout. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.
To know more about Banner Ads implementation in Android applications, check this Android Banner Ads with Examples.
Interstitial Ads are full-screen ads that cover the interface of an app until closed by the user. They're best used at natural pauses in the flow of an app's execution, such as in between levels of a game or just after completing a task.
To know more about Interstitial Ads implementation in android applications, check this Android Interstitial ad with Examples.
Rewarded video ads are full-screen video ads and it rewards the users for watching the ads.
To know more about Rewarded Video Ads implementation in android applications, check this Android Rewarded Video Ads with Examples.