Site Upgraded Marketizer Still Works
VN:F [1.9.11_1134]
Rating: +1 (from 1 vote)

{EAV_BLOG_VER:d5264a237aa2c5e8}image_thumb1

 

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

VN:F [1.9.11_1134]
Rating: 5.0/5 (1 vote cast)
AdMob 4.0.4 Tutorial, 5.0 out of 5 based on 1 rating

Related posts:

  1. AdMob Tutorial – Using AdMob SDK
  2. Android SDK – Adding AdMob
  3. WebView Template for Android SDK
  4. AI apk 2 Market
  5. Logcat
  • DJ PEP!

    Thanks man! great tutorial!

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)
  • http://twitter.com/Kajanking Kajan Warwick

    Thanks :D Finally able to make it work!

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)
  • 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?

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)
    • http://www.taiic.com Gene Kupfer

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

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
      • Typie34

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

        VA:F [1.9.11_1134]
        Rating: 0.0/5 (0 votes cast)
        VA:F [1.9.11_1134]
        Rating: 0 (from 0 votes)
  • 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.

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)

© 2011 App Inventor Info Center Suffusion theme by Sayontan Sinha
Content Protected Using Blog Protector By: PcDrome.

Optimized by SEO Ultimate