AdMob 4.0.4 Tutorial



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

Tutorial 1:

Tutorial 2:

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(;

// Initiate a generic request to load it with an ad

AdRequest adRequest = new 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.

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.



          <enum name="BANNER" value="1"/>

          <enum name="IAB_MRECT" value="2"/>

          <enum name="IAB_BANNER" value="3"/>

          <enum name="IAB_LEADERBOARD" value="4"/>


      "adUnitId" format="string"/>



The main.xml layout file is now a little different also.

"1.0" encoding="utf-8"?>











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 tag.


      android:configChanges="keyboard|keyboardHidden|orientation" />


And before the tag.


uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


Don’t forget to grab the source in my downloads at

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

You may also like...

  • DJ PEP!

    Thanks man! great tutorial!

  • Thanks 😀 Finally able to make it work!

  • Typie34

    im quite new to all this android dev stuff and your tools and tutorials helped me alot already, but can you do a tutorial to implement those ads into an “app inventor” app? i aready “marketized” my app and then tried to decompile the AI app with appmanager and added it to the eclipse project where i made the admob ads working. but thats probably the wrong way cause it istn really working. can you help me with that?

    • It’s currently not possible. There are a few things that need to be modified that are not accessible.

      • Typie34

        ah, this is sad 🙁
        hope they implement such a function to AI soon.
        thanks for your help.

  • Guest

    How do I get this magic “device id” so that only test ads are displayed?  (My app is currently displaying REAL ads all the time.)

    A few of my test devices are 1000 miles from here… so there’s no possible way I can “hook them all up to Ecplise/DDMS and view the log”.  Is that the ONLY way?

    What is the java code method to “get the device Id that setTestDevice needs”????

    All my SDKs, libs, executables are up-to-date as of today.

  • nice article