【问题标题】:Why are interstitial ads not showing on device为什么插页式广告未在设备上展示
【发布时间】:2022-02-03 03:57:09
【问题描述】:

我开发了一个 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'

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

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

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

【问题讨论】:

  • 您收到什么错误代码?检查 Logcat 输出。

标签: android admob interstitial


【解决方案1】:

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

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

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

这就是我声明插页式广告和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;
                }
            });

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

我认为这是问题所在。

【讨论】:

    【解决方案2】:
    AdRequest adRequest = new AdRequest.Builder().addTestDevice("deviceid").build();
    

    将此用于测试设备。

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        【解决方案4】:

        加载广告后致电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) {
                       
                    }
                });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多