Add Advertisements to Your Android Applications Using Admob

This guide is for developers who are interested in making money using advertisements. Use this guide to understand how to use AdMob to add advertisements in Android applications.

Steps

  1. Create an AdMob account by browsing to http://www.admob.com
  2. Once your AdMob account is created, Login to your account.
  3. Click on sites & Apps tab on the top menu. Then click on Add Site/App button to add the application you want your advertisements to show up on.
  4. Select the platform your created application is, in this case select Android.
  5. Enter the required details to add an app to the list. You should already know the application name and the package name for your application. Therefore write the name of your application in the app name field, and write the android package URL as market://details?id=<Package name>. Enter your package name by replacing the <Package name >. For category select what type of app your application is, and write a small description in the description box to tell what type of app it is. There is also an option to include Google ads, which can be useful to get ad fills when AdMob ads are not displayed.
  6. Once you hit continue, AdMob will add your application to the list and ask you to download the AdMob Android SDK. Click on the download button to download the SDK.
  7. While AdMob SDK is downloading, click on the go to Sites/Apps button to return to your list applications, then click on manage settings on the listed app to find your publisher ID.Save this information for future use in Eclipse to incorporate AdMob in your application.
  8. Extract the downloaded .Zip file with the AdMob Android SDK to an easily accessible location.
  9. Now start your Eclipse IDE to import the downloaded SDK. Find the folder containing your Android application and right click to choose properties option.
  10. Select “Java Build Path” option from the navigation plan to your left and then click on “libraries tab” to add the SDK file. Click on “Add external JARS…” button and locate the unzipped AdMob SDK JAR file on your disk, and add it to your project.
  11. If you successfully completed the previous step, you should now see the JAR file located under, Referenced Libraries folder inside your project.
  12. Once the SDK is added to your project, open the AndroidManifest.xml file located in your project. In order to use AdMob in your application you must include the following xml Just before the </application> tag enter a new activity for com.google.ads.AdActivity by adding this xml.<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />”
  13. After the </application> tag enter permissions that are required by AdMob.<uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  14. Open the project.properties file in your Android application folder and change this line of code at the end of the file to make AdMob SDK work. AdMob SDK requires android SDK-13, and since our application was SDK-7 we require changing the target version, target=android-13.
  15. Finally, to add an AdMob advertisement to your application, open your desired layout xml file. For this tutorial we will just add it to our main.xml located under res/layout folder of our project. Then add this following xml where you like to show your ad in your layout.
    • In <LinearLayout> tag add xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" After the <LinearLayout> tag add <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="YOUR PUBLISHER ID" ads:loadAdOnCreate="true" > </com.google.ads.AdView>
  16. Run your application and give it up to 5 minutes on initial run to have AdMob ads show on your application.



Tips

  • Latest AdMob SDK uses Android version 3.2 and up, therefore doing <uses-sdk android:minSdkVersion="7" /> in AndroidManifest.XML and adding target=android-13 in project.properties file will let you target your application to android versions less than 3.2.

Warnings

  • Make sure you put your own publisher ID, otherwise you will not get paid.

Things you will need

  • Working knowledge on Java, Eclipse and Android development and a computer.

Related Articles