开发者

Admob errors, can't get ads to show

I've been开发者_Python百科 trying for days without any results to get my admobs running.. I have been following the tutorial on http://code.google.com/mobile/ads/docs/android/banner_xml.html but can't seem to make it work..

My java file:

// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());

Manifest:

    </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"/>

Main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res/com.kai.custombutton"
          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="xxxxxxxxxxx"
                         ads:adSize="BANNER"/>

attrs.xml:

<?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>

I've added the admob sdk 4.0.4 also.. If anyone have a working code I would be very pleased if I could use it or if anyone could help me out!


Mine works using this:

ad = new AdView(this, AdSize.BANNER, "xxxadmobIDxxx");
LinearLayout layout =
            (LinearLayout) findViewById(R.id.main_admob_layout);

layout.addView(ad);
AdRequest request = new AdRequest();
request.setTesting(false);

ad.loadAd(request);

ad is a global, private AdView.


Check your AdMob account. Is your account receiving requests for impressions? If it is receiving requests, then your code is fine. It looks ok from my end, but I might be missing something. This was one of my older posts when I was struggling with adMob. It has my xml and java code that is currently working on my app.

If that's your real adUnit ID number in your code above, I'd get rid of it ASAP. There's no need for the rest of the world to know that number!


For those who needs a good tutorial on the newest admob sdk (4.0.4) look at this site: http://www.taiic.com/2011/04/27/admob-4-0-4-tutorial/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+taiic+%28App+Inventor+Info+Center%29

Helped me a lot!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜