android 检测广告代码,Admob测试广告未在Android应用程序中显示(示例代码)

正如标题所述,我正在尝试将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(Resource.Id.maintoolbar));

SupportActionBar.Title = "Rower Stuff";

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

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

SetUpViewPager(viewPager);

tabs.SetupWithViewPager(viewPager);

//sends request for ad

var adView = FindViewById(Resource.Id.adView);

var adRequest = new AdRequest.Builder().AddTestDevice("04255CCF937684AD80A0FC1CE8235CFB").Build();

adView.LoadAd(adRequest);

adView.BringToFront();

用于主要布局的XML:

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">

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@+id/adView">

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:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

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">

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值