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
- 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.
- 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 your are publishing your app to PlayStore.
Note: Using real Ad units while testing is against the AdMob poilicy.
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.
Download Source Code from below Link