Interstitial Integration for Xamarin Android
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:
- 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) { } }
- 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();
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();
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);
Done!
You can now deliver ironSource Interstitial Ads on your app!