In this tutorial, I have shared about how to implement AdMob Banner Ads in an Android Application. Before first brief Information about “AdMob”.
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 these ways
- Banner Ads: Basic ad format that appears at the top & bottom of the screen; can be automatically refreshed.
- Through Interstitial Ads: Full-page ad format that appears at natural break & transitions, such as level completion. Supports video content.
- Rewarded Video Ads: Ad format that rewards users for watching ads. Great for monetising free-to-play users. Video only.
- Native Ads: Customisable ad format that matches the look & feel of your app; appears inline with app content. Supports video content.
In this article, I will show you how to add Banner Ads in your Android Application.
I am also assuming that you are using Android Studio for developing your app and your project is kept opened in it.
Step 1. Open your project in Android Studio and add below line to your build.gradle dependencies
Step 2. Now rebuild the project Build->Rebuild project or click on sync now
Step 3. 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>
Step 4. 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);
Step 5. Now open strings.xml in values folder and add below line into your strings.
Please note replace banner ad unit id with yours and if you don’t have and don’t know how to get AdMob Banner Ad ID Click Here
Also note in this tutorial we used test ID under Banner AdMob 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 to test in your real device or on Emulator.
All the very Best.
Download Source Code from below Link