开发者

Unable to server AdMob ads on android using google SDK

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!


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>


try adding this permission line to your AndroidManifest.xml file

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


Friends, I meet the same problem today. I followed the whold google instruction. Finally, I got it. You can customize the request for call load. Like this:

AdRequest re = new AdRequest();
//re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE); 
adview.loadAd(re);

You can try my example, I put my apk and source code here:

Add Google Admob in Android Application

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜