
AdMob is a multi-platform mobile ad network that allows you to monetize your Android app. By integrating AdMob you can start earning right away. It is very useful particularly when you are publishing a free app and want to earn some money from it Integrating AdMob is such an easy task that it takes no more than 5mins. In this article, we’ll build a simple app with two screens to show the different types of ads that AdMob supports.
1. Type of AdMob Ads
Banner Ad
Banner Ads occupies the only portion of the screen depending on the ad size that is created. It comes in multiple sizes Standard, Medium, Large, Full-Size, Leaderboard, and Smart Banner. Smart banners are very useful when you target multiple device sizes and fit the same ad depending on the screen size.
Interstitial Ad
Interstitial ads occupy a full screen of the app. Basically, they will be shown on a timely basis, between screen transition or when the user is done with a task. Usually, we can see these ads in games displaying Ad when a level is completed.
Rewarded Video Ad
Rewarded Video Ads are fullscreen video ads which offer some reward points if the user watches the ad video. These ads are very useful to offer some reward points/coins in video games.
Native Ad
Native Ads offers flexibility to configure the ad appearance like color, text color and buttons to make them appear as a native component of the app.
2. Creating Ad Units
Note: AdMob admin interface changes quite often. The below steps to create Ad Unit IDs might differ from time to time.
1. Sign into your AdMob
2. Create a new App by giving the package name of the app you want to integrate AdMob. Once the App is created, you can find the APP ID on the dashboard which looks like ca-app-pub-XXXXXXXXX~XXXXXXXXX.
3. Select the newly created App and click on ADD AD UNITbutton to create a new ad unit.
4. Select the ad format and give the ad unit a name.
5. Once the ad unit is created, you can notice the Ad unit on the dashboard. An example of ad unit id look like ca-app-pub-0XXXXXXXXX/XXXXXXXXXXX
Open Your Admob Account and click on Apps And your Apps
Select on your app is publicsh or not in google play store or not if publice your app serch your app
Create Ads Type like Banner, Interstitial Rewarded Ads.
Step 1: First one to Start Android Studio
Step 2 : Seconds step to Create a New Project Project ClickOn ==> File ==> NEW ==> New Project
Step 3: Gradle Scripts Open Project base and add these
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' //noinspection GradleCompatible compile 'com.android.support:appcompat-v7:28+' compile 'com.android.support:design:28+' compile 'com.android.support:cardview-v7:28+' compile 'com.google.android.gms:play-services-ads:17.0.0'
4. Add the App ID and Ad unit IDs to your strings.xml. Open strings.xml located under res ⇒ values and add the IDs of all the ad units.
|
4. Create a class named MyApplication.java and extend the class from Application. In this application class, we have to globally initialize the AdMob App Id. Here we use MobileAds.initialize() method to initialize the AdMob.
3.1 Adding Banner Ad
Banner ads occupies only a portion of the screen. I am adding a banner ad in my main activity aligning to bottom of the screen. In order to add the banner ad, you need to add com.google.android.gms.ads.AdViewelement to your xml layout.
<
com.google.android.gms.ads.AdView
android:id
=
"@+id/adView"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
ads:adSize
=
"BANNER"
ads:adUnitId
=
"@string/banner_home_footer"
>
</
com.google.android.gms.ads.AdView
>
6. Open the layout file of your main activity (activity_main.xml) and add the AdView widget. I am also adding a button to launch another in which we’ll try Interstitial ad.
|
7. Open MainActivity.java and modify the code as shown.
|
3.2 Adding Interstitial Ad (Fullscreen Ad)
8. Create an activity named SecondActivity.java by right-clicking on package New ⇒ Activity ⇒ Empty Activity.
|
3.3 Adding Rewarded Video Ad
9. Create another activity named RewardedVideoAdActivity.java and add the below code. This is same as Interstitial but there will be a callback method onRewarded() called when there is a reward after watching the video ad completely.
|