请告诉我为什么看不到横幅广告。 屏幕随游戏一起显示,就像没有提供横幅一样。 错误不会发生。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new GraphicsView(), false);
AdView adView = new AdView(this, AdSize.BANNER, "a14fd65977f0c9f");
adView.loadAd(new AdRequest());
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(gameView);
layout.addView(adView, adParams);
setContentView(layout);
}
应用程序时写入的日志:
06-16 00:24:38.359: W/webcore(1236): Can't get the viewWidth after the first layout
06-16 00:24:38.639: I/Ads(1236): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=6766832335174985152&u_sd=1&slotname=a14fd65977f0c9f&u_w=320&msid=ru.bk.sobaka.n.e.k&cap=m&js=afma-sdk-a-v6.0.1&mv=4002306.com.android.vending&isu=ECF7E913C428C1C5F97C257CF153F328&cipa=0&format=320x50_mb&net=ed&app_name=1.android.ru.bk.sobaka.n.e.k&hl=ru&u_h=480&carrier=25001&ptime=0&u_audio=1&u_so=p&output=html®ion=mobile_app&u_tz=-240&ex=1&client_sdk=1&caps=interactiveVideo_clickTracking_sdkAdmobApiForAds&jsv=26" type: "admob" afmaNotifyDt: "null">
06-16 00:24:38.879: W/Ads(1236): IOException connecting to ad url.
06-16 00:24:38.879: W/Ads(1236): java.net.ConnectException: googleads.g.doubleclick.net/127.0.0.1:80 - Connection refused
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
06-16 00:24:38.879: W/Ads(1236): at java.net.Socket.connect(Socket.java:983)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
06-16 00:24:38.879: W/Ads(1236): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
06-16 00:24:38.879: W/Ads(1236): at com.google.ads.internal.f.b(SourceFile:428)
06-16 00:24:38.879: W/Ads(1236): at com.google.ads.internal.f.run(SourceFile:399)
06-16 00:24:38.879: W/Ads(1236): at java.lang.Thread.run(Thread.java:1019)
答案 0 :(得分:0)
这是我在Very Angry Robots中播放广告时使用的代码。在我的观点添加到布局之前,我没有要求加载广告。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
goFullScreen();
View gameView = createGameView();
AdView adView = createAdView();
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
layout.addView(adView, layoutParams);
layout.addView(gameView, layoutParams);
setContentView(layout);
startAdvertising(adView);
}
private AdView createAdView() {
AdView adView = new AdView(this, AdSize.BANNER, PUBLISHER_ID);
return adView;
}
private void startAdvertising(AdView adView) {
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(MY_PHONE);
adView.loadAd(adRequest);
}