Monday, June 18, 2012

AdMob Manager In Android Application

This is a sample activity which shows how to use AdMob Manager in your application.
Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Register or login at, and download GoogleAdMobAdsSdkAndroid-4.0.4, which contains a GoogleAdMobAdsSdk.jar file.
2.) Create a project MyAdMob.
3.) In your project’s root directory create a subdirectory lib. Copy the AdMob JAR (GoogleAdMobAdsSdk.jar) file into that lib directory.

4.) Right-click on your project from the Package Explorer tab and select Properties.
5.) Select Java Build Path from left panel and Select Libraries tab from the main window.
6.) Click on Add JARs.
7.) Select the JAR copied to the libs directory, Click OK to add the SDK to your Android project.
8.) Add some relevant permissions in AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""package="com.sample.MyAdMob" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
   <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MyAdMob" android:label="@string/app_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        <activity android:name=""android:configChanges="keyboard|keyboardHidden|orientation" />
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9.) Run the Application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. MyAdMob. Enter following information:
Project name: MyAdMob
Build Target: Android 2.1
Application name: MyAdMob
Package name: com.sample.MyAdMob
Create Activity: MyAdMob
On Clicking Finish MyAdMob code structure is generated with the necessary Android Packages being imported along with MyAdMob class will look like following:
package com.sample.MyAdMob;
import android.os.Bundle;
import android.widget.LinearLayout;
public class MyAdMob extends Activity
    private static final String MY_BANNER_UNIT_ID = "a14db01ee16f245";
   public void onCreate(Bundle savedInstanceState) {
        // Lookup R.layout.main
        LinearLayout layout = (LinearLayout)findViewById(;
        // Create the adView
        // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
        AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);
        // Add the adView to it
        // Initiate a generic request to load it with an ad
        AdRequest request = new AdRequest();
Output –The final output:

No comments:

Post a Comment