AdMob Advertising in Android Application/Game Step wise process

Following example shows step-by-step process to  how to integrate an AdMob advertisement into your Android application:

Step 1 If you are not already registered at AdMob, just visit the AdMob Website and create a new account. After the registration process you can see your empty AdMob dashboard. The screenshot below shows an empty AdMob dashboard:

Click on monetize new app then bellow screen will appear:

admob1

Step 2: Click on Add your app manually.Bellow Screen will show

admob2

Step 3: Click on Add App Button :next screen look like is as bellow:

admob3

Step 4:   Download Admob Android sdk: The AdMob Android SDK allows the developer to seamlessly integrate an advertisement within an Android based application. Download and unzip the Android jar archive (googleadmobadssdkandroid.zip). The archive contains the AdMob Android SDK for integrating an ad view into your Android user interface layouts (GoogleAdMobAdsSdk-6.1.0.jar).

Step 5: Let add admob jar file in your native application:googleadmobadssdkandroid.zip  unzip it and copy in lib folder in your anroid application:   Start Eclipse and create a new Android based Java application.   Create a /libs folder directly within the root folder of your Android project folder and copy the AdMob Android SDK jar into that folder. Right click on your project and add this library to your projects build path by selecting Build Path > Add External Archive…

The sample application consists of a simple main layout that contains a single TextView. Now we are going to modify this simple layout to contain an AdView. Therefore we add a new AdView as it is shown below:

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”

xmlns:ads=”http://schemas.android.com/apk/lib/com.google.ads”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:orientation=”vertical” >

<TextView

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:text=”@string/hello” />

 

<com.google.ads.AdView

android:id=”@+id/adview”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

ads:adSize=”BANNER”

ads:adUnitId=”a1501676c633fac”

ads:loadAdOnCreate=”true”

ads:testDevices=”TEST_EMULATOR, TEST_DEVICE_ID”

/>

</LinearLayout>

 

Step 6: Go to the AndroidManifest.xml file file open it and give the required permission:

Now add the Google AdActivity as well as both necessary permissions ACCESS_NETWORK_STATE and INTERNET to your AndroidManifest.xml file as it is shown here: 

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

<uses-permission android:name=”android.permission.INTERNET”/>

Code will look like bellow in AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>

<manifest xmlns:android=”http://schemas.android.com/apk/res/android”

package=”at.smartlab.androidbook.AdMobTest”

android:versionCode=”1″

android:versionName=”1.0″ >

 

<uses-sdk android:minSdkVersion=”15″ />

 

<application

android:icon=”@drawable/ic_launcher”

android:label=”@string/app_name” >

<activity

android:name=”.AdMobTestActivity”

android:label=”@string/app_name” >

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

</activity>

<activity android:name=”com.google.ads.AdActivity”

android:configChanges=”keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize”/>

</application>

 

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

<uses-permission android:name=”android.permission.INTERNET”/>

</manifest>

 

Step 7:To receive ads from AdMob you have to create an AdRequest instance within your own Activity and hand it over to your AdView layout element, as it is shown below:  

 

package at.smartlab.androidbook.AdMobTest;

 

import com.google.ads.AdRequest;

import com.google.ads.AdView;

 

import android.app.Activity;

import android.os.Bundle;

 

public class AdMobTestActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 

setContentView(R.layout.main);

 

// Look up the AdView as a resource and load a request.

AdView adView = (AdView)this.findViewById(R.id.adview);

adView.loadAd(new AdRequest());

}

}

Step 8: Copy the bellow code in layout/main.xml file 

<com.google.ads.AdView

android:id=”@+id/adview”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

ads:adSize=”BANNER”

ads:adUnitId=”a1501676c633fac”

ads:loadAdOnCreate=”true”

ads:testDevices=”TEST_EMULATOR, your test device ID goes here”

/>

 

To know the your test device ID goto the logcat file and copy it

The resulting Android app shows the demanded advert in combination with a HelloWorld TextView:

admob4

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *