Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to server AdMob ads on android using google SDK

Tags:

android

sdk

admob

I've been searching for the answer for a while, but I can't find the same set of circumstances, so I turn to you for help...

I'm trying to use the google SDK (not the admob sdk) to put ads in my android app. When running the app in the emulator, the log messages that I see are:

03-25 22:35:17.457: INFO/Ads(853): adRequestUrlHtml: [ contains two <script> tags ]
03-25 22:35:21.028: INFO/Ads(853): Received ad url: [ big long url ]

Sometimes I get:

03-25 22:35:21.828: INFO/Ads(853): onFailedToReceiveAd(No ad to show.)

which perhaps I can understand, but I also get:

03-25 22:50:56.817: INFO/Ads(1084): onFailedToReceiveAd(A network error occurred.)

If I hit the "big long url" above in my desktop browser, I get an ad about 1/2 the time and blank the other 1/2. (Hello, Dish Network) I never get an error.

I can browse the web with the emulator's browser, so the network component is working.

The app has internet privileges.

I'm frustrated with the lack of usable sample code - I see a lot of people using the old admob SDK and a few code fragments of people using the google SDK, but not a soup-to-nuts example/tutorial.

I've commented out the rest of my code, to no avail. Here's the main chunk of code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AdView adView = new AdView(this, AdSize.BANNER, ADMOB_PUBLISHER_ID);
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
    layout.addView(adView);
    AdRequest req = new AdRequest();
    // req.setTesting(true);
    adView.loadAd(req);
}

My manifest includes this:

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation"/>

and

<uses-permission android:name="android.permission.INTERNET" /> 

My main.xml contains this layout for the page:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/yellow"
android:id="@+id/mainLayout"
>

admob support hasn't replied.

Can anyone help me or at least refer me to the perfect google sdk guide for admob noobs?

Thanks!

like image 891
Alain Collins Avatar asked Mar 25 '11 23:03

Alain Collins


1 Answers

have you add attr.xml file???

<?xml version="1.0" encoding="utf-8"?>
 <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>
like image 55
romanzah Avatar answered Oct 03 '22 06:10

romanzah