【问题标题】:Show interstitial ad more than once多次展示插页式广告
【发布时间】:2016-06-03 14:15:02
【问题描述】:

请帮忙。插页式广告仅显示一次。我希望它显示得更多。

private void loadAds() {
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    interstitial = new InterstitialAd(this);
    AdRequest adRequest2 = new AdRequest.Builder().build(); //
    interstitial.setAdUnitId(getResources().getString(R.string.admob_interstitial));
    interstitial.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            AdLoaded = true;
        }

        @Override
        public void onAdClosed() {
            super.onAdClosed();
        }

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

    interstitial.loadAd(adRequest2);
}

public void displayInterstitial() {
    if (adsCounter == 0) {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
        adsCounter = 0;
    } else {
        adsCounter += 2;
    }
}

【问题讨论】:

    标签: android admob interstitial


    【解决方案1】:

    用这个回复OnAdClosed()

        @Override
              public void onAdClosed () 
              {
                  AdRequest adRequest = new AdRequest.Builder()
                    .build();
                  interstitial.loadAd(adRequest);
              }
    

    【讨论】:

      【解决方案2】:

      显示插页式广告后,您需要再次调用loadAd(adRequest) 才能加载新的插页式广告。

      【讨论】:

        【解决方案3】:

        对我来说,我必须调用 .destroy 并创建新实例。

        制作全局变量

        private MoPubInterstitial interstitial;
        

        将样板代码放在一个函数中:createInterstitialAd。

         private void createInterstitialAd(){
        
                // TODO: Replace this test id with your personal ad unit id
                interstitial = new MoPubInterstitial(getActivity(), "<#YOUR_AD_UNIT_ID#>");
                interstitial.setInterstitialAdListener(this);
                interstitial.load();
        
            }
        

        然后在广告加载失败或加载后调用的 InterstitialAdListener 方法中(注意:也在 onCreateView 中调用此方法

        interstitial.destroy();
           createInterstitialAd();
        

        【讨论】:

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