广告正在加载,但没有显示?

时间:2016-04-03 18:55:54

标签: java android database string admob

TL; DR:我的插页式广告已成功加载,但当我在其上调用.show()时,它们不会显示!

我已按照these个指示,广告成功加载,但在我致电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();
    }

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

P.S。我想我实际上已经让它早一点工作了,但从那以后它就停止了工作。可能是什么问题?

3 个答案:

答案 0 :(得分:0)

请将.addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")添加到AdRequestBuilder

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

因为在开发步骤中,如果您在AdMob上提出过多请求,有时会开始不显示广告。因此,在测试广告的开发过程中工作。如果它没有任何问题,当您在Play商店发布应用时,您的用户也会毫无问题地看到您的广告

答案 1 :(得分:0)

事实证明,我只需要在else之后删除额外的方法调用。例如,

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()**
      }

答案 2 :(得分:0)

尝试此代码

MobileAds.initialize(this, getString(R.string.admob_app_id));

private InterstitialAd mInterstitialAd;

mInterstitialAd = new InterstitialAd(this);

// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

loadInterstitialAds(mInterstitialAd);

 //Create loadInterstitialAds method
 public void loadInterstitialAds(final InterstitialAd mInterstitialAd) {
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                // Check the LogCat to get your test device ID
                .addTestDevice("Phone's ID")
                .build();

        // Load ads into Interstitial Ads
        mInterstitialAd.loadAd(adRequest);

        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
            }
        });
    }