如何在间隔或 3-4 次点击后在 webview 中显示插页式广告?

How to show interstitial ad in webview after some interval or 3-4 click?

我有一个 wordpress 网站,其中我有一个 webview 应用程序,我在任何按钮点击时都实现了插页式广告,所以每当点击 link 时,整页广告都会显示,我该如何减少它频率,我希望它在点击 3 或 4 次后表现良好?

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // The webView is about to navigate to the specified url.
            // Toast.makeText(MainActivity.this, "Login clicked", Toast.LENGTH_LONG).show();
            if (interstitialAd.isLoaded()) {
                interstitialAd.show();
                interstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdClosed() {
                        AdRequest adRequest = new AdRequest.Builder()
                                .build();
                        interstitialAd.loadAd(adRequest);
                    }
                });
            }
            return super.shouldOverrideUrlLoading(view, url);
        }

为了显示 Google 插页式广告,您需要应用一些条件。首先,您必须创建一个静态变量并将其值设置为 one

static counter = 1;

if (counter == 3){
// your interstitial code basically call its method show such as ad.show()
counter++;
}
else if (counter == 4){
// your interstitial code basically call its method show such as ad.show()
counter = 1;
}
else{
counter += 1;
}

编辑了以下内容

public static counter = 1;
@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // The webView is about to navigate to the specified url.
            // Toast.makeText(MainActivity.this, "Login clicked", Toast.LENGTH_LONG).show();
if(counter == 3)
            if (interstitialAd.isLoaded()) {
                interstitialAd.show();
                interstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdClosed() {
                        AdRequest adRequest = new AdRequest.Builder()
                                .build();
                        interstitialAd.loadAd(adRequest);
                    }
                });
            }
counter = 1;
}else{
  counter++;
}
            return super.shouldOverrideUrlLoading(view, url);
        }

我的问题的最终解决方案,欢迎任何建议...

int n = 1;
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // The webView is about to navigate to the specified url.

                if (interstitialAd.isLoaded()) {
                    if( n%3 == 0 )
                    {
                        interstitialAd.show();

           } n++;
                }
                interstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdClosed() {
                        AdRequest adRequest = new AdRequest.Builder()
                                .build();
                        interstitialAd.loadAd(adRequest);
                    }
                });
                return super.shouldOverrideUrlLoading(view, url);
            }