AdMob响应消息为null或零长度

时间:2011-03-20 14:49:49

标签: android admob

所以,我一直试图在我的应用程序中实现AdMob API几天,我基本上复制并粘贴了提供的基本示例代码。它似乎有效,但我不断获得onFailedToReceiveAd(A network error occurred).Response is null or zero length.

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="ragingsoftware.android.AdsTest"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation"/>

</application>
</manifest>

这是我的主要布局xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayoutMain">
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent"></LinearLayout>
</LinearLayout>

这是我的活动代码:

private void initAds() {
    // Create the adView
    AdView adView = new AdView(this, AdSize.BANNER, "XXXXXXXXXXXXXXX");
    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.LinearLayoutMain);
    // Add the adView to it
    layout.addView(adView);
    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());
}

最后,但并非最不重要的是,logcat:

03-20 00:48:37.569: INFO/Ads(12511): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"msid":"ragingsoftware.android.WiFiScheduler","hl":"en","preqs":0,"u_so":"p","slotname":"a14d83d19c4eaef","js":"afma-sdk-a-v4.0.2","app_name":"4.0.2.android.ragingsoftware.android.WiFiScheduler","isu":"358ABB21689377B8D76F4A16B987E097","u_audio":1,"u_w":320,"format":"320x50_mb","u_sd":1.0,"net":"ed","u_h":480});</script></head><body></body></html>
03-20 00:48:39.059: INFO/Ads(12511): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?msid=ragingsoftware.android.WiFiScheduler&hl=en&preqs=0&u_so=p&slotname=a14d83d19c4eaef&js=afma-sdk-a-v4.0.2&app_name=4.0.2.android.ragingsoftware.android.WiFiScheduler&isu=358ABB21689377B8D76F4A16B987E097&u_audio=1&u_w=320&format=320x50_mb&u_sd=1&net=ed&u_h=480&output=html&region=mobile_app&u_tz=240&ex=1&client_sdk=1", "afmaNotifyDt": "null">
03-20 00:48:42.599: INFO/Ads(12511): AdLoader timed out while getting the HTML.
03-20 00:48:42.599: INFO/Ads(12511): onFailedToReceiveAd(A network error occurred.)
03-20 00:48:42.619: INFO/Ads(12511): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"msid":"ragingsoftware.android.WiFiScheduler","hl":"en","preqs":1,"u_so":"p","slotname":"a14d83d19c4eaef","js":"afma-sdk-a-v4.0.2","app_name":"4.0.2.android.ragingsoftware.android.WiFiScheduler","isu":"358ABB21689377B8D76F4A16B987E097","u_audio":1,"u_w":320,"format":"320x50_mb","u_sd":1.0,"net":"ed","u_h":480});</script></head><body></body></html>
03-20 00:48:43.179: INFO/Ads(12511): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?msid=ragingsoftware.android.WiFiScheduler&hl=en&preqs=1&u_so=p&slotname=a14d83d19c4eaef&js=afma-sdk-a-v4.0.2&app_name=4.0.2.android.ragingsoftware.android.WiFiScheduler&isu=358ABB21689377B8D76F4A16B987E097&u_audio=1&u_w=320&format=320x50_mb&u_sd=1&net=ed&u_h=480&output=html&region=mobile_app&u_tz=240&ex=1&client_sdk=1&askip=1", "afmaNotifyDt": "null">
03-20 00:48:47.630: INFO/Ads(12511): AdLoader timed out while getting the HTML.
03-20 00:48:47.649: INFO/Ads(12511): onFailedToReceiveAd(A network error occurred.)
03-20 00:48:47.869: INFO/Ads(12511): Response message is null or zero length: 
03-20 00:48:48.119: INFO/Ads(12511): Response message is null or zero length: 
03-20 00:50:00.219: INFO/Ads(12511): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"msid":"ragingsoftware.android.WiFiScheduler","hl":"en","preqs":2,"u_so":"p","slotname":"a14d83d19c4eaef","js":"afma-sdk-a-v4.0.2","app_name":"4.0.2.android.ragingsoftware.android.WiFiScheduler","isu":"358ABB21689377B8D76F4A16B987E097","u_audio":1,"u_w":320,"format":"320x50_mb","u_sd":1.0,"net":"ed","u_h":480});</script></head><body></body></html>
03-20 00:50:00.219: INFO/Ads(12511): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"msid":"ragingsoftware.android.WiFiScheduler","hl":"en","preqs":2,"u_so":"p","slotname":"a14d83d19c4eaef","js":"afma-sdk-a-v4.0.2","app_name":"4.0.2.android.ragingsoftware.android.WiFiScheduler","isu":"358ABB21689377B8D76F4A16B987E097","u_audio":1,"u_w":320,"format":"320x50_mb","u_sd":1.0,"net":"ed","u_h":480});</script></head><body></body></html>
03-20 00:50:00.909: INFO/Ads(12511): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?msid=ragingsoftware.android.WiFiScheduler&hl=en&preqs=2&u_so=p&slotname=a14d83d19c4eaef&js=afma-sdk-a-v4.0.2&app_name=4.0.2.android.ragingsoftware.android.WiFiScheduler&isu=358ABB21689377B8D76F4A16B987E097&u_audio=1&u_w=320&format=320x50_mb&u_sd=1&net=ed&u_h=480&output=html&region=mobile_app&u_tz=240&ex=1&client_sdk=1&askip=2", "afmaNotifyDt": "null">
03-20 00:50:00.909: INFO/Ads(12511): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?msid=ragingsoftware.android.WiFiScheduler&hl=en&preqs=2&u_so=p&slotname=a14d83d19c4eaef&js=afma-sdk-a-v4.0.2&app_name=4.0.2.android.ragingsoftware.android.WiFiScheduler&isu=358ABB21689377B8D76F4A16B987E097&u_audio=1&u_w=320&format=320x50_mb&u_sd=1&net=ed&u_h=480&output=html&region=mobile_app&u_tz=240&ex=1&client_sdk=1&askip=2", "afmaNotifyDt": "null">
03-20 00:50:05.248: INFO/Ads(12511): AdLoader timed out while getting the HTML.
03-20 00:50:05.249: INFO/Ads(12511): onFailedToReceiveAd(A network error occurred.)
03-20 00:50:05.248: INFO/Ads(12511): AdLoader timed out while getting the HTML.
03-20 00:50:05.249: INFO/Ads(12511): onFailedToReceiveAd(A network error occurred.)
03-20 00:50:05.509: INFO/Ads(12511): Response message is null or zero length: 

我一直在谷歌搜索几天,但找不到答案。我很感激任何帮助。

4 个答案:

答案 0 :(得分:1)

您必须将测试模式设置为true才能在模拟器上显示测试广告。

LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
AdView adView = new AdView(this, AdSize.BANNER, " a14e01a2c440ee1");
layout.addView(adView);
AdRequest request = new AdRequest();
**request.setTesting(true);**    
adView.loadAd(request);

答案 1 :(得分:0)

乍一看,在我看来,您在清单中遗漏了AdMob分配的应用程序的发布商ID。您需要添加如下的元数据字段:

<meta-data android:value="ADMOB_ID" android:name="ADMOB_PUBLISHER_ID" />

其中ADMOB_ID是AdMob指定的ID。

答案 2 :(得分:0)

我在Android上遇到了同样的错误&lt; 2.0,但适用于Android&gt; 2.0。我目前正在模拟器上进行测试。 Admob SDK应该与Android 1.5兼容,但它看起来没有!

答案 3 :(得分:0)

我是android的新手,我的回答可能对你没有帮助,但据我所知,admob sdk在几个时间间隔后发送添加请求,所以你可以试试adwhirl

https://www.adwhirl.com/doc/android/AdWhirlAndroidSDKSetup.html

AdWhirl for Android SDK通过最多四个移动广告网络的简单集成,最大限度地提高了应用的广告收入:

1)AdMob 2)Google AdSense移动应用程序 3)Millennial Media 4)ZestADZ