1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > android 检测广告代码 Admob测试广告未在Android应用程序中显示(示例代码)

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

时间:2019-09-27 04:37:49

相关推荐

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="/apk/res/android"

xmlns:app="/apk/res-auto"

xmlns:tools="/tools"

xmlns:ads="/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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。