Question

I want to Display a Interstitial Ad after every one minute... can any one please explain with sample code ...

thanks Please

    interstitialAds = new InterstitialAd(this, "Your_Pub_ID");
    final AdRequest adRequest = new AdRequest();
    interstitialAds.loadAd(adRequest);
    interstitialAds.setAdListener(this);
Was it helpful?

Solution 3

There are numerous way to display Interstitial ads at regular interval of time. You can add codes in your app in order to display Interstitial ads at regular interval of time.


prepareAd();

    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) strongly stopping you to doing such stuffs. It is against AdMob policy and your account will get suspended if you do so.

If you want to learn more stuffs about android app development and how to place admob ad in your application. I recommend you to visit this website.

http://www.elegantespace.com/how-to-load-interstitial-ad-at-regular-interval-of-time/

OTHER TIPS

Firstly this will be a VERY bad experience for your users. I would strongly recommend against it.

But if you really want to piss your users off then something like:

final Runnable runanble = new Runnable() {
  public void run() {
    while (true) {
      wait(60000);
      runOnUiThread(intersitial.showAd());
      interstitial.loadAd(new request());
    }
  }
};

Edit: DO NOT DO THIS. I have had word back from Admob that this directly contravenes their policies and it will get your account disabled.

This is against admob policies and they will ban you also this will be very bad experience for user.

EDIT: link to policy (refer "Repeated or recurring interstitials" section) - https://support.google.com/admob/answer/6201362?hl=en&ref_topic=2745287

place it in oncreate method

handler.postDelayed(runnable, 420000);

after oncreate method

Runnable runnable = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
//Your code to show add
// Create the interstitial.
// Prepare the Interstitial Ad
Interstitial = new InterstitialAd(your activity);
// Insert the Ad Unit ID
interstitial.setAdUnitId("your id ");

//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) findViewById(R.id.ad_view);

// Request for Ads
AdRequest adRequest = new AdRequest.Builder()

// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();

 // Load ads into Banner Ads
 adView.loadAd(adRequest);

 // Load ads into Interstitial Ads
 Interstitial.loadAd(adRequest);

 // Prepare an Interstitial Ad Listener
 interstitial.setAdListener(new AdListener() {
 public void onAdLoaded() {
 // Call displayInterstitial() function
 displayInterstitial();
 }
 });
 handler.postDelayed(this, 600000); // 1000 - Milliseconds
 }
 };
interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
        public void run() { 
            MainActivity.this.interstitialAd.show();
        } 
    }, 5000);
} });

just simple. create Timertask and schedule every 60000 ms. but it is bad UX for users. don't do it

final Handler handler = new Handler();
    Timer timer = new Timer();
    TimerTask doAsynchronousTask = new TimerTask() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    if (mInterstitialAd.isLoaded()) {
                        mInterstitialAd.show();
                    }
                }
            });
        }
    };
    timer.schedule(doAsynchronousTask, 0, 60000);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top