How to stop loading banner ads?

Some users intentionally try to repeatedly click banner ads. In this regard, we are faced with the problem of suspension or termination of the account. Does anyone know how to stop the ad from loading if it crosses a limit (e.g. 3).

    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .setRequestAgent("android_studio:ad_template").build();

    adView.loadAd(adRequest);
    if(currentbannerclick>3)
    {

       // some code to not load the ad.
    }
+4
source share
5 answers

LinearLayout id = container AdView id = adView

    if(currentbannerclick>3)
    container.removeView(adView);

Thank you all for your reply.

+1
source

, Ad, . , adView.loadAd(adRequest);, , .

0

:

private void loadAd() {
    // This is a one element array because it needs to be declared final
    // TODO: you should probably load the default value from somewhere because of activity restarts
    final int[] currentBannerClick = {0};

    final AdView adView = (AdView) findViewById(R.id.adView);
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdOpened() {
            super.onAdOpened();
            currentBannerClick[0]++;
            if (currentBannerClick[0] > 3) {
                adView.setVisibility(View.INVISIBLE);
                adView.destroy();
            }

            // TODO: save currentBannerClick[0] somewhere, see previous TODO comment
        }
    });

    if (currentBannerClick[0] <= 3) {
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(YOUR_DEVICE_ID).build();
        adView.setVisibility(View.VISIBLE);
        adView.loadAd(adRequest);
    } else {
        adView.setVisibility(View.INVISIBLE);
    }
}
0

, AdMob. 3 , .

0
source

All Articles