Android working with AdMob Banner Ad

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.

Open your project in Android Studio

Add below line to your build.gradle dependencies

1

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

1

2

3

4

5

6

7

8

9

<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

1

2

3

AdView mAdView=(AdView)findViewById(R.id.adView);

AdRequest adRequest=newAdRequest.Builder().build();

mAdView.loadAd(adRequest);

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