AdMob的广告在视图永远不会显示 [英] Admob ad never displays in View

查看:138
本文介绍了AdMob的广告在视图永远不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让AdMob的广告在我的Andr​​oid应用程序显示和一直未能如愿。我曾接触过他们的支持,并没有收到将近一个星期的任何回应,所以我想我现在要问在这里帮助。

I am trying to get AdMob ads to display in my android application and have been unable to do so. I have contacted their support and have not received any response in almost a week, so I figured I would now ask for help here.

首先,一些code:
的Andr​​oidManifest.xml

First some code:
AndroidManifest.xml

<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:versionCode="1" package="com.foo.application">
  <application>
    <meta-data 
        android:value="admob-publisher-id-here" 
        android:name="ADMOB_PUBLISHER_ID" />
  </application>

  <uses-permission android:name="android.permission.INTERNET" />
</manifest>

AdMob的出版商-ID-这里是在实际的清单文件我真正的发布者ID。

Yes, admob-publisher-id-here is my real publisher id in the actual manifest file.

main_layout.xml

<LinearLayout 
    android:id="@+id/adhost" 
    android:layout_width="fill_parent"
    android:padding="5dip" android:layout_height="wrap_content"
    android:minHeight="20dip" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.foo.application">
  <com.admob.android.ads.AdView 
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      app:backgroundColor="#000000" 
      app:primaryTextColor="#FFFFFF" 
      app:secondaryTextColor="#CCCCCC"
      app:keywords="android at&amp;t t-mobile iphone blah"/>
</LinearLayout>

attr.xml

<resources>
  <declare-styleable name="com.admob.android.ads.AdView">            
    <attr name="backgroundColor" format="color" />
    <attr name="primaryTextColor" format="color" />
    <attr name="secondaryTextColor" format="color" />
    <attr name="keywords" format="string" />
    <attr name="refreshInterval" format="integer" />
  </declare-styleable>
</resources>

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.admob.android.ads.AdManager;
import com.admob.android.ads.AdView;

import com.foo.application.R;

public class MainActivity extends Activity {
  private AdView ad;

  public MainActivity ( ) {
        AdManager.setTestDevices ( new String[] {
      // made this up for this
            "012345678994814751742145548AAAAAAA" 
        } );
        AdManager.setTestAction ( "url" );
    }

    @Override
    public void onCreate ( Bundle savedInstanceState ) {
      super.onCreate ( savedInstanceState );
        setContentView(R.layout.main_layout);

        if ( AdManager.isTestDevice ( this ) ) {
          // this logs
            Log.w ( "foo-app", "we are on a test device" );
        }

        ad = ( AdView ) this.findViewById ( R.id.ad );
        if ( ad != null ) {
            ad.setVisibility ( View.VISIBLE );
            ad.setAdListener ( new AdListener () );
        }
    }
}

AdListener.java

package com.foo.application

import android.util.Log;

import com.admob.android.ads.AdView;
import com.admob.android.ads.SimpleAdListener;

class AdListener extends SimpleAdListener {
    @Override
    public void onFailedToReceiveAd ( AdView adView ) {
      // this is what logs
        Log.w ( "foo-app", "failed to receive ad" );
        super.onFailedToReceiveAd ( adView );
    }

    @Override
    public void onFailedToReceiveRefreshedAd ( AdView adView ) {
        Log.w ( "foo-app", "failed to receive refreshed ad" );
        super.onFailedToReceiveRefreshedAd ( adView );
    }

    @Override
    public void onReceiveAd ( AdView adView ) {
        Log.w ( "foo-app", "receive ad" );
        super.onReceiveAd ( adView );
    }

    @Override
    public void onReceiveRefreshedAd ( AdView adView ) {
        Log.w ( "foo-app", "receive refreshed ad" );
        super.onReceiveRefreshedAd ( adView );
    }
}

在logcat中,我看到以下内容:

In the logcat, i see the following:

INFO/AdMobSDK(29541): To get test ads on this device use AdManager.setTestDevices( new String[] { "012345678994814751742145548AAAAAAA" } )
WARN/AdMobSDK(29541): Ignoring requestFreshAd() because we are requesting an ad right now already.
WARN/AdMobSDK(29541): Ignoring requestFreshAd() because we are requesting an ad right now already.
WARN/foo-app(29541): we are on a test device
WARN/foo-app(29541): failed to receive ad

的AdListener是表明它是无法检索广告。我有一个有效的数据连接,再加上我在测试模式,所以它应该是始终显示广告,根据 AdMob的维基。有在logcat中没有错误,也不是施加力闭合的。

The AdListener is indicating that it is unable to retrieve the ad. I have an active data connection, plus I am in Test Mode, so it is supposed to always show an ad, according to the admob wiki. There are no errors in the logcat, nor is the application force closing at all.

任何人有任何的想法还是你看到的东西,我做错了什么?

Anyone have any ideas or do you see something I am doing wrong?

更新:我从AdMob的响应,可是他们说的是我创建的aeveiw两次,这我不是

推荐答案

Admob的应该已经包括以此为戒,但我离题...

Admob should have included this as a warning, but I digress...

在布局你有安卓填充=5dip这当然会导致手机,如G1到丢失他们的一些可用的屏幕房地产(下文320dip宽度)。这当然是的最小宽度为admob的广告,从而导致失败。然后调用 onFailedToReceiveAd 与任何没有解释的听众。

In your layout you have android:padding="5dip" this of course causes phones like the G1 to 'lose' some of their available screen real-estate (below 320dip width). Which is of course the minimum width for an admob ad, causing it to fail. Then calling onFailedToReceiveAd in the listener with no explanation whatsoever.

日志仅包含

WARN/AdMobSDK(347): Ignoring requestFreshAd() because we are requesting an ad right now already.

解决方法是简单的,不使用填充或利润率在你的布局包含广告的根源。采取了一些试验,但它的作品。

The fix is simple, don't use padding or margins in the root of your layouts that contain ads. Took some experimentation, but it works.

这篇关于AdMob的广告在视图永远不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆