简体   繁体   中英

Delay showing an ad in Admob

I'm wondering if it is possible to delay the showing of an interstitial ad in Admob? I want to display the ads at natural breaking points in the app, but only after the user has spent 5 minutes using the app. Does anyone know whether this is possible and/or against AdMob policy?

Thank you!

Yes. It is possible.

First, you load the Ad.

mInterstitialAd = new InterstitialAd(MainActivity.this);
mInterstitialAd.setAdUnitId(/* AD UNIT ID */);
mInterstitialAd.loadAd((new AdRequest.Builder()).build());

Then, to show the InterstitialAd:

if (mInterstitialAd.isLoaded()) {
    mInterstitialAd.show();
}

As you can see, you first load the Ad and then you show it. Loading the ad won't add it to the screen.

So, you can invoke mInterstitialAd.show() whenever you want (after 5 minutes as you said) to actually display it.

You can set as interval your ads with this code

    ScheduledExecutorService scheduler =
        Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {

    public void run() {
        Log.i("hello", "world");
        runOnUiThread(new Runnable() {
            public void run() {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                   Log.d("TAG"," Interstitial not loaded");
                }

                prepareAd();


            }
        });

    }
}, 20, 20, TimeUnit.SECONDS);

However, I (you can say that admob)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM