2011-03-20 67 views
5

因此,我一直試圖在我的應用中實施AdMob API幾天,而且我基本上已經複製並粘貼了提供的基本示例代碼。這似乎是工作,但我不斷收到onFailedToReceiveAd(A network error occurred).Response is null or zero length.AdMob響應消息爲空或零長度

這裏是我的清單文件:

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

我一直在Google上搜索幾天,無法找到答案。我會很感激任何幫助。

+0

也許你是在屏蔽廣告? – 2011-03-23 22:16:09

回答

0

乍一看,我認爲您在清單中缺少由AdMob分配的應用程序發佈者ID。您需要添加元數據字段是這樣的:

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

ADMOB_ID是AdMob的分配ID。

+0

我使用的SDK不同,但我認爲「XXXXXXXXXXXXXXX」是他的ID。 – 2011-03-20 15:44:58

+0

我按照您的建議添加了,而且我仍然看到我的原始帖子中描述的錯誤消息。我也看到這些: 'AdLoader在獲取HTML時超時' 和 'BufferedReader構造函數中使用的默認緩衝區大小。如果需要8k字符的緩衝區,最好是明確的。' – RagingSoftware 2011-03-20 15:58:12

+0

您可以忽略緩衝區大小相關的消息 - 其原因在某些其他區域中可以定義。 – 2011-03-20 16:31:02

0

我得到了相同的錯誤爲Android < 2.0,但它適用於Android> 2.0。我目前正在模擬器上測試。 Admob SDK應該與Android 1.5兼容,但它看起來不像!

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); 
0

我爲Android新功能,我的回答可能不幫助你,但按我的知識AdMob SDK的發送數的時間間隔後添加請求,這樣你們可以與AdWhirl相

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

的嘗試對於AdWhirl中Android SDK中通過多達四個的移動廣告網絡整合瑣碎最大化您的應用程序的廣告收入:

1)的AdMob 2)谷歌AdSense移動應用廣告 3 )Millennial Media 4)ZestADZ