{EAV_BLOG_VER:d5264a237aa2c5e8}![]()
People have been asking me to take a look at the latest AdMob SDK, version 4.0.4. Some have been having trouble getting it to work and other’s have had problems getting test ads to show up.
I did some digging and I put together a working template. I won’t go through the entire process of creating this. Please reference my other two tutorials if you want a full walkthrough. I’ll just point out the changes and I’m also including the source as always on my download page at http://www.taiic.com/downloads.
Tutorial 1: http://www.taiic.com/2011/03/22/android-sdk-adding-admob/
Tutorial 2: http://www.taiic.com/2011/04/12/admob-tutorial-using-admob-sdk/
So it looks to me that one of the major differences is that they have moved the ability to configure most of the settings to xml, and are now using a smaller footprint in the java file. Here is all the code that is needed in the .java.
// Look up the AdView as a resource and load a request.
AdView layout = (AdView)this.findViewById(R.id.adView);
// Initiate a generic request to load it with an ad
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true);
layout.loadAd(adRequest);
Ok, so here is where the testing part has changed. At first I was hitting my head against the wall wondering why this isn’t working, and then I stumbled across this.
http://code.google.com/mobile/ads/docs/android/intermediate.html#istesting
Specifically, “It’s ignored on devices so there’s no need to worry about leaving it in production.” So…I unplugged my phone, loaded up in the emulator and presto, I had a test ad.
My guess is they had one to many support complaints about test ads loading in live apps and decided to remove that possibility all together.
The other change is in the attrs.xml file. It now looks like this.
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="adSize">
<enum name="BANNER" value="1"/>
<enum name="IAB_MRECT" value="2"/>
<enum name="IAB_BANNER" value="3"/>
<enum name="IAB_LEADERBOARD" value="4"/>
</attr>
<attr name="adUnitId" format="string"/>
</declare-styleable>
</resources>
The main.xml layout file is now a little different also.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.taiic.template.admob"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="YOUR_PUBLISHER_ID"
ads:adSize="BANNER"/>
</LinearLayout>
Notice how it uses the attributes defined in the attrs.xml, adUnitID and adSize.
And finally, the AndroidManifest.xml has been cleaned up as well.
The following shows up above the </application> tag.
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation" />
And before the </manifest> tag.
<uses-permission android:name="android.permission.INTERNET"/>
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Don’t forget to grab the source in my downloads at http://www.taiic.com/downloads
Join our community on facebook. Just hit the Like in the left sidebar (towards the top of the page), this button
Or directly on our fb page at http://www.facebook.com/pages/tAIICcom/116243311786911
Related posts:
-
DJ PEP!
-
http://twitter.com/Kajanking Kajan Warwick
-
Typie34
-
http://www.taiic.com Gene Kupfer
-
Typie34
-
Guest

Youtube
tAIIC Forums
RSS
Twitter
Facebook