为什么插页式广告未在设备上展示

Why are interstitial ads not showing on device

我开发了一个 Android 应用程序并集成了 Google 的 adMob 插页式广告。问题是在模拟器上广告成功显示,但在我的设备上没有显示。我创建了在 AdMob 上创建的广告单元 ID,并将该应用链接到 adMob。

这是我的代码:

InterstitialAd mInterstitialAd;

mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
        AdRequest adRequest = new AdRequest.Builder().build();
        // Load ads into Interstitial Ads
        mInterstitialAd.loadAd(adRequest);
        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {
                showInterstitial();
            }
        });

现在 showInterstitial() 函数:

private void showInterstitial() {
    Random r = new Random();
    if (mInterstitialAd.isLoaded()) {
        new android.os.Handler().postDelayed(
                new Runnable() {
                    public void run() {

                        mInterstitialAd.show();
                        AdRequest adRequest = new AdRequest.Builder().build();
                        mInterstitialAd.loadAd(adRequest);
                    }
                },
                r.nextInt(7000 - 5000) + 5000);

    }
}

我添加了一个随机超时,当广告加载时就会显示。

并在我的 gradle 文件中添加了以下内容:

compile 'com.google.android.gms:play-services-ads:9.8.0'

注意。我在应用程序中有另一个横幅广告。

在模拟器上它工作得很好这是一个截图:

有人知道为什么插页式广告没有在设备上显示吗? .谢谢。

创建广告请求时使用 'addTestDevice("")' 方法。

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

创建新广告后,可以通过查看 logcat 输出来获取 deviceId。 在日志中查找 "ads" 标记,它会在请求广告时显示 addTestDevice("some value")。

我解决了这个问题,但改变了我调用 showInterstitial() 函数的方式。问题与广告的加载有关。这是我的修复:

  @Override
    public void onResume() {
        // Start or resume the game.
        super.onResume();
        showInterstitial();
    }
    @Override
    protected void onStart() {
        super.onStart();
        showInterstitial();
    }

我在 Activity 开始或恢复时显示广告,我们需要一个事件来显示广告。

这就是我声明插页式广告和 showInterstitial() 函数的方式:

//Interstitial
            private InterstitialAd mInterstitialAd;
            mInterstitialAd = new InterstitialAd(this);
            mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_interstitial));
            AdRequest adRequestInterstitial = new AdRequest.Builder().addTestDevice("deviceid").build();
            mInterstitialAd.loadAd(adRequestInterstitial);

            mInterstitialAd.setAdListener(new AdListener() {
                @Override
                public void onAdClosed() {

                }

                @Override
                public void onAdLoaded() {
                    mAdIsLoading = false;
                    showInterstitial();
                }

                @Override
                public void onAdFailedToLoad(int errorCode) {
                    mAdIsLoading = false;
                }
            });

这是我在三星设备上的结果:

我认为这是问题所在。

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

将其用于测试设备。

加载广告后调用 mInterstitialAd.show();

   private function showInterstitial()

        private InterstitialAd mInterstitialAd;
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_interstitial));
        AdRequest adRequestInterstitial = new AdRequest.Builder().addTestDevice("deviceid").build();
        mInterstitialAd.loadAd(adRequestInterstitial);

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
               
            }

            @Override
            public void onAdLoaded() {
                mInterstitialAd.show();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
               
            }
        });