Interstitial Ads Integration for Android

Do go through the steps in our Getting Started Guide to add Media.Net SDK into your project before starting the integration of Interstitial Ads.

For adding interstitial ads to your app, following are the steps:

  • Load an interstitial ad
  • Setting up listeners

    a. Add these lines to load interstitial ad

    Create an instance of InterstitialAd class in your activity.

          InterstitialAd interstitialAd = new InterstitialAd(this,"XXXXXXXXX") //Enter ad unit id
    

    Set ad type for showing relevant ads like banner or video

          interstitialAd.setSizes(new AdSize(300, 250));
          interstitialAd.load();
    

    b. Listen to interstitial ad state

          interstitialAd.addListener(new InterstitialListener() {
    
               // Sent when the interstitial ad is shown.
               @Override public void onInterstitialShown() {
                     //Do your stuff   
               }          
    
               // Sent when the ad slot successfully retrieved an interstitial ad.
               @Override public void onAdLoaded() {
                    //Do your stuff            
               }
    
               // Sent when the ad slot has failed to retrieve an ad.
               @Override public void onError(final MNetError error) {
                    //Do your stuff
               }
    
               // Sent when the user has tapped on the Interstitial ad.
               @Override public void onAdClicked() {
                    //Do your stuff             
               }
    
               // Sent when the user closes the Ad
               @Override public void onAdClosed() {
                    //Do your stuff     
               }
          });
    

Interstitial Video Ads Integration for Android

InterstitialAd can display video ads too. To enable video ads in InterstitialAd you will have to contact your Media.Net account manager.

InterstitialAd provides a listener interface (VideoListener) which can be used to stay informed about the video ad lifecycle events. VideoListener has the following methods.

interstitialAd.addVideoAdListener(new VideoAdListener() {
	// Sent when video ad started
  @Override public void onVideoStarted() {
    // Do your stuff
  }

  // Sent when video ad completed
  @Override public void onVideoCompleted() {
    // Do your stuff
  }
});