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.
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.
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).
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 .
Figure 4
Go to your project folder (in Eclipse), and right click to your project (Figure 5). Choose Properties.
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.
Figure 6
Figure 7
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
- Official Documentation (which is not updated timely) - http://code.google.com/mobile/ads/docs/android/fundamentals.html
- Official Discussion (AdMob SDK 4.0.10) - http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1
- 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
I think that attrs.xml file is not used anymore in version 4.1.0, so it's not needed. Also setTesting method is being deprecated.
ReplyDeleteDear Anonymous,
ReplyDeleteThanks for the comment. I'll check and update this post later...
So far the hands-on provided here is working...
ReplyDeleteHi,
ReplyDeleteCan you take a look at the following question from stackoverflow.com ?
http://stackoverflow.com/questions/5038158/main-activity-is-not-garbage-collected-after-destruction-because-it-is-referenced
I seem to get this behavior ONLY when i load the AdView in my activity. Even an empty Activity with just the AdView widget takes tons of memory and I see with HPROF that what's keeping it from being released is that the InputMethodManager holds a reference to it (Which I didn't add anywhere...)
Another related question on the same memory issue:
ReplyDeletehttp://stackoverflow.com/questions/6148812/android-admob-causes-memory-leak
I've added the code and i'm not getting any add..
ReplyDeleteI've changed ads:adUnitId="YOUR_PUBLISHER_ID_HERE" for ads:adUnitId="xxxxxxxxxxxxx" the x's stand for the Publisher Id.
After waiting 4 minutes on my phone im not getting any ads?
Dear Christian,
ReplyDeleteMaybe you could share with me the project folder, I'll check it for you.
Email me at khirulnizam[a]gmail.com
I found that it's not working in the emulator. You need to test the admob ads in a real Android phone.
ReplyDeleteTry to add: adRequest.addTestDevice("314321C010A54CE800467089A3E155E6");
ReplyDeleteLook for this code in LogCat while you start the app.
salam kenal sob, info: buat rekan2 yang ingin pasang mobgold/admob dengan java script di halaman html silahkan kunjungi http://wapads.idwap.net terimakasih
ReplyDeletemake sure to setTesting() to false, when you deploy the apps...
ReplyDeleteAdView adview = (AdView)findViewById(R.id.adView1);
AdRequest re = new AdRequest();
re.setTesting(false);//this must be false when apps is released in the market
adview.loadAd(re);
Can you tell me how to put an ads banner in the preview screen for a live wallpaper?As in the Fireflies live wallpaper (http://www.livewallpapers.org/fireflies-free-1543/), I don't know how to put an ads banner in the Preview screen (not Settings screen).
ReplyDeleteWhen I install the Fireflies wallpaper on my HTC which is on Android 2.2.1 the banner shows up in both Preview and Settings screens, but on my two other Sony Ericsson (on 2.3.3) I can only see the banner in the Setting screens. Does that have something to do with Sony Ericsson or the version of Android?
Thanks.
My app is telling me I need to have AdActivity declared in AndroidManifest with configChanges. but added the lines:
ReplyDeleteAny clue what is wrong?
ok so I found out that eclipse wants me to change to android:configChanges="keyboard|keyboardHidden|orientation|screenlayout|uiMode|screenSize|smallestScreenSize"/> but when I do this, it says string types not allowed.
ReplyDeleteRefer to this post for AdMob SDK 6.x http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html
DeleteRefer to this post for AdMob SDK 6.x http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html
ReplyDeleteAll the best...
I have added this sample code to my app and it work perfect on my device, I saw my first admob ads for a brief moment in fact how many times evry time I run the app on my device but when it goes to the next activity it will not display the next screen and would totally kills the whole app. it say it stopped unexpectedly. can you help me. thanks.
Deletealso in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.
ReplyDeletealso in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.
ReplyDeletesorry to add this again anyway, I have a fatal error: NoAPI database founf in null comment in my error log. I guess thats what it starts but how come it works when I dont have the admob insert. do I have to include something before going to the next activity. again sir thanks a million to your help.
ReplyDeleteIt's difficult for me to debug the error without having to look at the source code and the error message personally...
DeleteWondering whether you install AdMob 4.x or AdMob 6.x...
Delete