Utkarsh Sharma
Utkarsh Sharma

Reputation: 19

how to set time to load interstitial ads in android?

I am using adsmob sdk first time. I don't know how to load ads as I want to load. Here is my code:

    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    InterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

    adRequest = new AdRequest.Builder().build();

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

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });
}

private void showInterstitial() {
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}

Upvotes: 0

Views: 7636

Answers (1)

Mustansir
Mustansir

Reputation: 2515

Your admob account will get banned if you use timer to popup interstitial ads.

If you want to show interstitial ad after an event try this: Example if you are using webview, and want to show interstitial, after page has loaded:

Public class ads extends AppCompatActivity {
 InterstitialAd mInterstitialAd;

 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

      //This is where you initialize ads
      mInterstitialAd = new InterstitialAd(this);
      mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxx");
      //This function request new Interstitial.
      requestNewInterstitial();


     myWebView.setWebChromeClient(new WebChromeClient() {
     public void onProgressChanged(WebView view, int newProgress) {
      progress.setProgress(newProgress);
       progress.setVisibility(View.VISIBLE);

         if (newProgress == 100) {

         progress.setVisibility(View.GONE); 
       // Interstitialads is shown after calling mInterstitial.show()
           mInterstitialAd.show();              
           }
         }

         }
    );

 }
//This function initializes new ads.
 private void requestNewInterstitial() {
    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);
 }

 }

Upvotes: 1

Related Questions