2011-05-22 50 views
1

就像標題所說,我正在請求廣告,它們正在填充,但從未顯示。我甚至啓用了一個房子廣告只是爲了確保。我已經搞了2天了,現在找不到解決方案。我知道最近用admob改變了一些事情,並且不再需要attrs.xml來使它工作,現在有一堆沒有結果的代碼。任何幫助,將不勝感激!Admob請求工作和100%填充,未顯示在應用程序

Java代碼:

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     //admob 
     //AdView adView = (AdView)findViewById(R.id.adView1); 
     AdView adView = new AdView(this, AdSize.BANNER, "a14dd7f0258a8b7"); 
     AdRequest re = new AdRequest(); 
     re.setTesting(true); 
     adView.loadAd(re); 
     //end admob 
    } 

AndroidManifest.xml中

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:debuggable="false" 

    android:description="@string/description"> 
     <activity 
        android:label="@string/app_name" 
        android:screenOrientation="portrait" 
        android:name=".Index"> 
      <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> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
</manifest> 

main.xml中

<LinearLayout 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:orientation="vertical" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<com.google.ads.AdView 
android:id="@+id/adView1" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
ads:adSize="BANNER" 
ads:adUnitId="a14dd7f0258a8b7" 
ads:loadAdOnCreate="true"/> 


(buttons here) 
</LinearLayout> 

更新:logcat的=

05-22 15:57:22.882: WARN/Ads(294): Invalid adSize parameter in XML layout: -1. Defaulting to BANNER. 
05-22 15:57:22.892: ERROR/Ads(294): AdView missing required XML attribute adUnitId. 
05-22 15:57:23.512: INFO/Ads(294): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":1,"u_sd":1.5,"u_w":480,"slotname":"a14dd7f0258a8b7","simulator":1,"msid":"com.robores.elect","cap":"m,a","js":"afma-sdk-a-v4.0.4","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","net":"ed","app_name":"4.0.4.android.com.robores.elect","hl":"en","u_h":800,"testing":1,"u_so":"p","u_audio":4});</script></head><body></body></html> 
05-22 15:57:25.113: INFO/Ads(294): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=1&u_sd=1.5&u_w=480&slotname=a14dd7f0258a8b7&msid=com.robores.elect&cap=m%2Ca&js=afma-sdk-a-v4.0.4&isu=B3EEABB8EE11C2BE770B684D95219ECB&format=320x50_mb&net=ed&app_name=4.0.4.android.com.robores.elect&hl=en&u_h=800&u_so=p&u_audio=4&adtest=on&output=html&region=mobile_app&u_tz=0&ex=1&client_sdk=1&askip=1", "afmaNotifyDt": "null"> 
05-22 15:57:25.763: INFO/global(294): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 
05-22 15:57:25.913: DEBUG/dalvikvm(294): GC_FOR_MALLOC freed 6570 objects/467056 bytes in 94ms 
05-22 15:57:25.953: DEBUG/webviewglue(294): nativeDestroy view: 0x291bf8 
05-22 15:57:25.953: DEBUG/webviewglue(294): nativeDestroy view: 0x291a40 
05-22 15:57:26.513: WARN/webcore(294): Can't get the viewWidth after the first layout 
05-22 15:57:26.563: INFO/Ads(294): onReceiveAd() 
+0

嘗試fill_parent,只是爲了確保您的adview沒有被隱藏。 – stealthcopter 2011-05-22 14:36:46

+0

填寫家長在哪裏? android:width-「填充父母」? – Xarddrax 2011-05-22 14:44:06

+0

就在adview上,所以沒有辦法隱藏它。 – stealthcopter 2011-05-22 14:44:51

回答

2

您使用的是哪個版本的admob庫。 GoogleAdMobAdsSdk-4.1.0.jar和GoogleAdMobAdsSdk-4.0.4.jar有一些區別。

我最近從4.0.4更新。到4.1.0,不得不改變一些代碼行。目前我已經得到了幾乎完全相同的代碼,與4.1.0中沒有任何問題相同。

0

這個工作對我來說:

ad = new AdView(this, AdSize.BANNER, ADMOB_KEY); 
      LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout); 
      // Add the adView to it 
      layout.addView(ad); 
      AdRequest request = new AdRequest(); 
      request.setKeywords(MosaicCommon.AD_KEYWORDS); 

你不必在你的addView(..)部分。

+0

這是導致部隊關閉對我來說:/ – Xarddrax 2011-05-22 16:01:09

+0

什麼是logcat錯誤信息? – Haphazard 2011-05-22 17:01:42

+0

不需要將AdView添加到佈局,因爲它來自main.xml – stealthcopter 2011-05-27 13:30:38

0

使用以下內容,我修復了這個錯誤。

<com.google.ads.AdView 
android:id="@+id/adView" 
android:layout_width="320dp" 
android:layout_height="50dp" 
android:gravity="center" 
ads:adUnitId="my id goes here" 
ads:adSize="BANNER" 
ads:loadAdOnCreate="true"/> 
相關問題