Installing Google AdMob into Android Apps

Previously I wrote on why ads are needed to help maintaining an app. Read the article here http://blog.kerul.net/2011/05/generating-revenue-from-free-mobile.html.

---This is quite an old article. You may find the latest supporting AdMob 6.x in here http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html ---

This is quite a long tutorial, there are 3 major steps involved. The experiment is done using Windows 7, Eclipse Helios and AdMob SDK 4.1.0 (which currently is the latest-during time of writing).

STEP 1: Get the ads from AdMob.com

To display the AdMob ads in your Android mobile apps, you need to register first at the admob.com . After completing the registration, login and Add Site/App. Refer to Figure 1.

image

Figure 1

Choose the desired platform and fill in the details (as in Figure 2). Just put http:// in the Android Package URL if your app is not published in the market yet. And click Continue.

ScreenHunter_16 May. 16 08.35

Figure 2

Download the AdMob Android SDK, and save the zip file in your machine. Make sure to extract the file and save it to your hard disk (anywhere is possible).

ScreenHunter_17 May. 16 08.36

Figure 3

STEP 2: Install the AdMob SDK into your Android project.

The most important file in the AdMob Android SDK that you download is GoogleAdMobAdsSdk-4.1.0.jar . Currently it’s in version 4.1.0 .

ScreenHunter_18 May. 16 08.40

Figure 4

Go to your project folder (in Eclipse), and right click to your project (Figure 5). Choose Properties.

image

Figure 5

Click the Java Build Path on your left. Choose the Libraries in the tab, and click Add External JARs. Locate the JAR file (GoogleAdMobAdsSdk-4.1.0.jar). And click OK.

image

Figure 6

image

Figure 7

image

Figure 8

STEP 3: The codes to display ads in your app.

Add some additional activity and permissions in the manifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.android.calc"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Calc"
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"/>
</application>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="4" />

</manifest>


Create attr.xml file in the res/values 


 


 


Related links



  1. Official Documentation (which is not updated timely) - http://code.google.com/mobile/ads/docs/android/fundamentals.html
  2. Official Discussion (AdMob SDK 4.0.10) - http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1
  3. A very good tutorial for AdMob SDK 4.0.4 - http://android.jmsliu.com/209/add-google-admob-in-android-application.html?utm_source=rss&utm_medium=rss&utm_campaign=add-google-admob-in-android-application

Popular Posts

WorldConferences.net