就像标题所说,我正在申请广告,他们正在填补,但从未显示过。我甚至启用了一个房子广告,以确保。我现在已经拧了2天了,无法找到解决方案。我知道最近使用admob更改了一些内容,并且不再需要attrs.xml来使其工作,现在有一堆没有结果的代码。任何帮助将不胜感激!
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®ion=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 :(得分:2)
您使用的是哪个版本的admob lib。 GoogleAdMobAdsSdk-4.1.0.jar与GoogleAdMobAdsSdk-4.0.4.jar之间存在一些差异。
我最近从4.0.4更新。到4.1.0并且不得不改变一些代码行。目前我的代码几乎与上面描述的完全相同,但4.1.0没有问题。
答案 1 :(得分: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(..)
部分没有。
答案 2 :(得分: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"/>