广告正在加载,但未展示?

2022-01-25 00:00:00 string database android java admob

我的插页式广告已成功加载,但是当我对它们调用 .show() 时,它们没有显示出来.

My interstitial ads are successfully loading, but when I call .show() on them, they don't show up.

我已按照 这些 说明操作,广告加载成功,但是当我调用 mInterstitialAd.show();:

I have followed these directions, and the ads load successfully, but don't show when I call mInterstitialAd.show();:

在 onCreate() 中:

 mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("My ID");

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

requestNewInterstitial():

  private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice("Phone's ID")
                .build();

        mInterstitialAd.loadAd(adRequest);
    }

问题来了:

 public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }

        beginPlayingGame();
    }

我收到日志说它已加载到我的日志猫中,但广告实际上并未显示!为什么会加载,但不显示?

I get the log saying it is loaded in my log cat, but the ad doesn't actually show! Why is it loading, but not showing?

附:我想我实际上更早地让它工作了一次,但从那以后它就停止了工作.可能是什么问题?

P.S. I think I actually got it to work once earlier, but it stopped working ever since then. What could be the problem?

推荐答案

原来我只需要删除 else 之后的额外方法调用.例如,

It turns out that I just had to remove the extra method call after the else. For example,

public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }

        beginPlayingGame();
    }

应该是

public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }
    //NOTICE THERE Is NO EXTRA METHOD CALL OF **beginPlayingGame()**
      }

相关文章