AdMob is one of the most popular, high paying and world’s largest mobile advertising networks. AdMob is multi platform mobile advertising network that allows you to monetize from your android, iPhone, iOS, windows and others mobile application and game. If you’ve published a free app to the app store and want to earn money, AdMob is one of the great ways to earn extra money from your free games and apps. In this tutorial, you will learn to integrate Google AdMob step by step to your android application or game and display banner and full screen (Interstitial) ads.
Integrating Google AdMob to your app or game is very easy; you don’t need to know any more advanced thing. Currently AdMob supports four types of ads; banner, interstitial (full screen), rewarded interstitial and native ads.
YouTube Android API Integration: Getting Started with YouTube Android API
Google Maps Android API Getting Started Tutorial : Part 1
Load Images Using Picasso Library in Android
Android Integration Example: How to Integrate Google AdMob to Android to Earn Money from Free Apps and Games
Open existing project or create new project to integrate AdMob and earn money by displaying ads on your application.
1. Sign in to AdMob Account and Create Ad Units
1.1. If you already have AdMob account then sign in to it and if you don’t have then create a new account.
1.2. Click on Monetize tab and select or create new app.
1.3. If you’ve already published your app to the play store, you can search app or developer from search for your app tab.
1.4. If you want to add your app manually (not published yet) click on add your app manually tab and give your app name and choose platform. Or you can select from apps you have already added.
1.5. Select Banner ad format and give name to ad unit and then click save button. There is other setting like ad type, automatic refresh, text ad style.
1.6. Likewise, again create a new Interstitial (full screen) ad unit.
1.7. After creating ad units, you can see the Ad Unit ID on the dashboard which looks like: ca-app-pub-5717827144758520/8297887893
You can create other many ad units if required for your app.
2. Adding Google Play Services Dependency, Ad units ID
2.1. Open your app build.gradle file and add compile ‘com.google.android.gms:play-services-ads:8.4.0’ dependency. Build.gradle file will look like below.
2.2. Now open your strings.xml from res/values/ and add your ads unit ID to your app strings.xml file.
3. Modifying AndroidManifest.xml File
Open AndroidManifest.xml file and add the android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE user permission, google play services version meta-data and AdActivity with android:theme and android:configChanges attributes. Following is the complete content of AndroidManifest.xml file.
4. Adding AdMob Footer Banner Ad in Android Application
Banner ad can be added on any place on the screen. In this example project I am adding banner ad at the bottom/footer of screen.
4.1. Open your XML layout file and add com.google.android.gms.ads.AdView inside RelativeLayout with attributes like android:id, android:layout_width, android:layout_height, android:layout_centerHorizontal, android:layout_alignParentBottom, ads:adSize, ads:adUnitId. Following is the complete code of XML layout file.
4.2. Open your java activity file and add following code. Don’t forget to change test device id with your device id. Follow the step 6 to get your device id to enable testing ads on your device only.
5. How to Enable Test Ads of AdMob in Android Application
AdMob policies do not allow you to click on your own live ads. If you click your own ads google may suspend your account. To protect your account from being suspended, you can use test ads while developing. For that, you need to provide your testing device id, I have added my device id like above .addTestDevice(“4DD0986B8BB49093161F4F00CF61B887 “) and if you are testing app on emulator add .addTestDevice(AdRequest.DEVICE_ID_EMULATOR). To get your device ID to enable AdMob test ad follow step 6.
6. How to Get My Android Device (Real Phone) ID for AdMob Test Ads
6.1. To get your real device id for AdMob test ad, first replace Device ID with some text like .addTestDevice(“Device ID”) in MainActivity.java file and run your application.
6.2. After running your application on real device, open logcat and search for addTestDevice. You will see like AdRequest.Builder.addTestDevice(“4DD0986B8BB49093161F4F00CF61B887”) in your logcat, 4DD0986B8BB49093161F4F00CF61B887 is your device ID.
6.3. Add device ID in addTestDevice of your java activity file like step 4.
Now run your application, you will see Google AdMob test ad at the bottom of screen like below screenshot.
7. How to Add Full screen Ad (Interstitial Ad) of AdMob in Android Application and Game
7.1. Create a new java activity file call it ActivityTwo.java and add fullscreen ad (Interstitial Ad) code in your activity file. ActivityTwo.java file will look like below.
7.2. Create a new XML file activity_two.xml and add following code.
Now run your Google AdMob Android Integrate application, you will see google banner ad on bottom/footer of home screen and if you click the Open Interstitial (Fullscreen) Ad, you will be able to see full screen ad on your application.
Download Complete Project
You can download complete example project of How to Integrate Google AdMob in Android from GitHub.
Download AdMob Example App From PlayStore