Admobs测试广告未显示在android应用程序中

时间:2018-09-02 13:03:04

标签: c# android xamarin xamarin.android admob

正如标题所述,我正在尝试在我的应用程序中实现admob广告,但是当我使用未展示的测试广告时。

启动画面活动:

base.OnCreate(savedInstanceState);

//Ensures that the SDK has been initialized with our publisher app ID
var id = "xxxx";
Android.Gms.Ads.MobileAds.Initialize(ApplicationContext, id);

//Starts main part of app
StartActivity(new Intent(Application.Context, typeof(MainActivity)));

然后转到包含我的应用程序主要部分的主要活动:

base.OnCreate(savedInstanceState);

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);

//sets up the the toolbar and tabs
SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.maintoolbar));
SupportActionBar.Title = "Rower Stuff";

TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);

ViewPager viewPager = FindViewById<ViewPager>(Resource.Id.viewpager);

SetUpViewPager(viewPager);

tabs.SetupWithViewPager(viewPager);

//sends request for ad
var adView = FindViewById<AdView>(Resource.Id.adView);
var adRequest = new AdRequest.Builder().AddTestDevice("04255CCF937684AD80A0FC1CE8235CFB").Build();
adView.LoadAd(adRequest);
adView.BringToFront();

主要布局的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout       
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView">
        <android.support.v7.widget.Toolbar
            android:id="@+id/maintoolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </android.support.v4.view.ViewPager>    
    </LinearLayout>
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>

adUnitId设置为'ca-app-pub-3940256099942544/6300978111',这是提供的测试标语。

当我在手机(即测试设备)上启动我的应用程序时,广告不会展示。

调试时出现这些错误...

I/Ads     ( 7518): Starting ad request.

09-02 13:59:53.617 I/Ads     ( 7518): This request is sent from a test device.

09-02 13:59:53.619 W/Ads     ( 7518): Not retrying to fetch app settings

09-02 13:59:54.028 I/Ads     ( 7518): Instantiating mediation adapter: com.google.DummyAdapter

09-02 13:59:54.029 I/Ads     ( 7518): No fill from any mediation ad networks.

09-02 13:59:54.075 I/Ads     ( 7518): Scheduling ad refresh 60000 milliseconds from now.

09-02 13:59:54.075 W/Ads     ( 7518): Failed to load ad: 3

1 个答案:

答案 0 :(得分:0)

首先,检查您是否正确实施了横幅广告

请按照以下步骤操作:

  1. 删除AddTestDevice()并将设置广告单元ID设置为“ ca-app-pub-3940256099942544 / 6300978111”,将应用程序ID设置为“ ca-app-pub-3940256099942544〜3347511713”,以检查您是否正确实现了广告单元。
  2. 如果横幅广告有效,请添加AddTestDevice()并使用在AdMob网站中创建广告单元时提供给您的广告单元ID和应用ID。您无需在此处使用测试广告单元ID,因为您已经在使用AddTestDevice()。