Interstitial Integration for Xamarin Android

Before you start Make sure you have correctly integrated the ironSource Xamarin Plugin in your application. Integration is outlined here.

Step 1. Implement the Interstitial Video Listener

The ironSource SDK fires several events to inform you of your Interstitial activity. To receive these events, we suggest the following:

  1. Create a class which inherits from LevelPlayInterstitialDelegate. It is recommended create a separate class for each delegate.
    public class LevelPlayInterstitial : Activity, ILevelPlayInterstitialListener
        {
            private Activity activity;
            public LevelPlayInterstitial(Activity activity)
            {
                this.activity = activity;
            }
       // Invoked when end user clicked on the interstitial ad
                public void OnAdClicked(AdInfo adInfo)
                {
                }
       // Invoked when the interstitial ad closed and the user went back to the application screen.
                public void OnAdClosed(AdInfo adInfo)
                {
                }
       // Indicates that the ad failed to be loaded 
                public void OnAdLoadFailed(IronSourceError ironSourceError)
                {
                }
       // Invoked when the Interstitial Ad Unit has opened, and user left the application screen.
       // This is the impression indication. 
                public void OnAdOpened(AdInfo adInfo)
                {
                }
     // Invoked when Interstitial Ad is ready to be shown after load function was called.
                public void OnAdReady(AdInfo adInfo)
                {
                }
     // Invoked when Interstitial ad failed to show.
                public void OnAdShowFailed(IronSourceError ironSourceError, AdInfo adinfo)
                {
                }
    //Invoked when Interstitial ad has successfully shown  
            public void OnAdShowSucceeded(AdInfo adInfo)
            {
            }
    }

  2. Create and instantiate a LevelPlayInterstitial object. Set the delegate using the new object and start listening to ILevelPlayInterstitialListener.
    Make sure to call the  SetLevelPlayInterstitialListener before the init response.
    LevelPlayInterstitial mLevelPlayInterstitial;
    // Define the listener 
    mLevelPlayInterstitial = new LevelPlayInterstitial(this);
    // Set the delegate
    IronSource.SetLevelPlayInterstitialListener(mLevelPlayInterstitial);
    

  • Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from ironSource’s callbacks need to be passed to the main thread before executing.

Step 2. Load Interstitial Ad

We recommend requesting an Interstitial Ad a short while before you plan on showing it to your users as the loading process can take time.
To request an interstitial ad, call the following method:

IronSource.LoadInterstitial();

Note:  If you’d like to serve several Interstitial Ads in your application, you must repeat this step after you’ve shown and closed the previous Interstitial Ad. Once the onInterstitialAdClosed function is fired, you will be able to load a new Interstitial ad.

Step 3. Check Ad Availability

After you call the LoadInterstitial in Step 2, you will be notified when the ad is loaded and ready to be shown to your user through the delegate with the method OnAdReady which will inform you about ad availability.

public void OnAdReady(AdInfo adinfo){}

In addition, you can also ask for the ad availability directly by calling the following function:

IronSource.IsInterstitialReady();

We don’t recommend making consecutive requests for an interstitial ad in a short timespan. Numerous requests in a short period of time have no added value as the chance of available inventory at this time is unlikely.

Step 4. Show Interstitial Ad

Once you receive the OnAdReady callback, you are ready to show an Interstitial Ad to your users. Invoke the following method to serve an Interstitial ad to your users:

IronSource.ShowInterstitial();

You can also show Interstitial and specify the placement you would like to watch:

IronSource.ShowInterstitial(placementName);
Important! Once you’ve successfully completed step 4, you will have shown your user an Interstitial Ad. In the case you want to serve another Interstitial ad, you must repeat Step 3 to request an additional Interstitial.

Done!
You can now deliver ironSource Interstitial Ads on your app!