How to Implement AdMob banner Ads in Android Application

Banner

How to Implement AdMob banner Ads in Android Application

1030 662 AlDeCode

AdMob is a mobile advertising company founded by Omar Hamoui. The name AdMob is a portmanteau for “advertising on mobile”. It was incorporated on April 10, 2006, while Hamoui was in business school at Wharton.

AdMob is very familiar to all the Android developers even for a beginner. AdMob gives you income through revenue generated by displaying Ads on Your App in two ways

  1. Displaying Banner Ads
  2. Through Interstitial Ads

In this article, I will show you how to add Banner Ads in your Android Application assuming that you are using Android Studio for developing your app and your project is kept opened in it. Please watch video for better understanding.

Step 1. Open your project in Android Studio and add below line to your build.gradle dependencies

compile 'com.google.android.gms:play-services-ads:8.4.0'

Now rebuild the project Build->Rebuild project or click on sync now

In project structure, Navigate to activity_main.xml and paste following code in your Layout

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

Open MainActivity.java add below lines inside onCreate method

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Now open strings.xml in values folder and below line into your strings.

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>

To know how to get AdMob Banner Ad ID Click Here

Banner AdMob ID used here is test ID which shows Test ads. You can use your real AdMob Banner Id when you are publishing your app to PlayStore.

Note: Using real Ad units while testing is against the AdMob policy.

Now we successfully implemented AdMob Banner Ad in your Android App. Run the app export as apk and test in your real device or on Emulator.

Content Source: Study Warehouse

Leave a Reply