用的是GoogleAdMobAdsSdk-4.0.4.jar,Android SDK 2.2:
AndroidManifest.xml配置如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hxsd.admobdemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<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>
<meta-data android:value="a14f435ee615be1" android:name="ADMOB_PUBLISHER_ID" />
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation"></activity>
</application>
</manifest>
MainActivity如下:
package com.hxsd.admobdemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class MainActivity extends Activity {
AdView adView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = new AdView(this, AdSize.BANNER, "a14f435ee615be1");
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
layout.addView(adView);
AdRequest request = new AdRequest();
//request.setTesting(true);
adView.loadAd(request);
}
}
我用真机测试,广告始终显示不出来,Log日志如下:
02-23 10:54:55.926: I/Ads(19540): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"u_w":540,"slotname":"a14f435ee615be1","msid":"com.hxsd.admobdemo","cap":"m","js":"afma-sdk-a-v4.0.4","isu":"D5D04A7D3B4097D8A22DB36E70415F52","format":"320x50_mb","net":"wi","app_name":"4.0.4.android.com.hxsd.admobdemo","hl":"zh","u_h":960,"u_so":"p","u_audio":1});</script></head><body></body></html>
02-23 10:55:55.925: I/Ads(19540): AdLoader timed out while getting the URL.
02-23 10:55:55.925: I/Ads(19540): onFailedToReceiveAd(A network error occurred.)
跪求高手指点。。。。。。
请求超时了,你看下网络是否有问题。
还有你这模拟请求看看参数是否足够了。
wifi没有问题啊
参数我是按sdk的例子写的
呜呜~~~~~
@囧囧囧囧: 你要先看看你能否访问Google ad