【问题标题】:Interstitial AdMob opens after closing插页式 AdMob 在关闭后打开
【发布时间】:2019-04-07 11:38:24
【问题描述】:

我使用 Interstitial AdMob 创建了一个应用程序,但是当它打开广告并关闭它时,它又重新打开,依此类推...我想做的是在 5 次启动计数应用程序后抛出广告。这是我的代码。

    sharedPreferences = getPreferences(0);
    int count = sharedPreferences.getInt("numRun", 0);
    count++;
    sharedPreferences.edit().putInt("numRun", count).commit();

    MobileAds.initialize(this, "ADMOB_ID");
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.INTERSTITIAL_ID));

    mInterstitialAd.loadAd(new AdRequest.Builder().build());

    mInterstitialAd.setAdListener(new AdListener(){
        @Override
        public void onAdLoaded() {
            int count = sharedPreferences.getInt("numRun", 0);

            if (count == INTERSTITIAL_LAUNCH) {
                count = 0;
                sharedPreferences.edit().putInt("numRun", count).commit();
                mInterstitialAd.show();
            }
        }
        @Override
        public void onAdClosed() {
            // Code to be executed when the interstitial ad is closed.
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
        }
    });

其中 INTERSTITIAL_LAUNCH 是 4 的整数。

【问题讨论】:

    标签: android admob interstitial


    【解决方案1】:

    你说INTERSTITIAL_LAUNCH 是 4 的整数。

    当您对照此值检查变量count 时,根据代码,如果其值大于 4,则广告也会显示。

    替换为:

    if (count == 5)
    

    【讨论】:

    • 你是对的!另外,问题是我没有设置count = 0,所以只要它得到5,它仍然是5......等等。谢谢!
    • 您也可以设置每次广告展示后计数为 0 以继续循环。
    • 如果我想在网页浏览量为 15 的页面加载计数时投放广告怎么办?如何控制 webview 访问页面的计数? @Gourav
    • 这也很简单。增加滑动刷新监听器中变量的值。如果您还有其他问题,请提出新问题。这个只是用于广告
    • 同样,我问的是插页式广告,但不是 5 个启动计数应用程序,而是 15 个通过 webview 访问的页面。
    猜你喜欢
    • 1970-01-01
    • 2020-09-25
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多