AdMob广告未显示 [英] AdMob Ads Not Showing

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

问题描述

因此,我使用Play Services SDK实施了AdMob广告。
我已经完成了书籍的所有内容,但广告不会显示。

So, I implemented AdMob ads with the Play Services SDK. I've done everything 'by the book', but the ads won't show.

如果我将AdView背景设置为白色,则会显示空白区域,但不会显示广告。
我正在使用Fragments,但我将AdView放在 activity_main.xml 中(尽管在片段中我设置了60dp的边距)底部)

If I set the AdView background to white, it shows the white space but not the Ad. I'm using Fragments, but I'm putting the AdView in the activity_main.xml (although in the fragments I've set a margin of 60dp at the bottom)

这是我的 onCreate 代码(包含实际代码和'测试'代码)

Here's my onCreate code (with the actual code and the 'testing' code)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);

    drawer.openDrawer(Gravity.LEFT);

    mNavigationDrawerFragment = (NavigationDrawerFragment)
            getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
            R.id.navigation_drawer,
            (DrawerLayout) findViewById(R.id.drawer_layout));

    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("Device_ID")
            .build();
    adView.loadAd(adRequest);
}

这是我的 activity_main.xml

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.MainActivity">


<RelativeLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/adView" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adUnitId="Unit_ID"
        ads:adSize="BANNER"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

<fragment
    android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="com.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />

我缺少什么?

推荐答案

我认为除了你已有的这个区块外:

I think in addition to this block that you already have:

AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("Device_ID")
        .build();

...你遗失了这样的东西:

...You are missing something like this:

    AdView adView = (AdView) this.findViewById(R.id.adView);
    adView.loadAd(adRequest);

这是完整的图片:


  1. xml文件中的内容:

  1. what is in xml file:

<com.google.android.gms.ads.AdView android:id="@+id/adView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  ads:adUnitId="your ad unit id"
  ads:adSize="BANNER"/>


  • onCreate中的内容:

  • what is in onCreate:

    AdRequest adRequest = new AdRequest.Builder()
            .build();
    
    AdView adView = (AdView) this.findViewById(R.id.adView);
    adView.loadAd(adRequest);
    


  • 请注意以上代码用于制作。您必须使用测试设备ID进行测试,以避免AdMob处罚。

    Please note the code above is for production. You must use test device id for testing in order to avoid AdMob penalties.

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

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