### Kotlin Interstitial Ad Implementation Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration This Kotlin code provides a full implementation of interstitial ads, mirroring the Java example. It covers ad instance creation, listener setup, ad loading, and ad display, including variations for showing ads with or without a specific placement name. It also includes the required listener callbacks. ```kotlin class InterstitialAdActivity : Activity(), LevelPlayInterstitialAdListener { private lateinit var mInterstitialAd: LevelPlayInterstitialAd fun createInterstitialAd() { mInterstitialAd = LevelPlayInterstitialAd("adUnitId") mInterstitialAd.setListener(this) } fun loadInterstitialAd() { mInterstitialAd.loadAd() } fun showInterstitialAd() { if (mInterstitialAd.isAdReady()) { mInterstitialAd.showAd(this) } } fun showInterstitialAd(placementName: String) { // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { mInterstitialAd.showAd(this, placementName) } } // LevelPlayInterstitialAdListener methods override fun onAdLoaded(adInfo: LevelPlayAdInfo) {} override fun onAdLoadFailed(error: LevelPlayAdError) {} override fun onAdInfoChanged(adInfo: LevelPlayAdInfo) {} override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {} override fun onAdDisplayFailed(error: LevelPlayAdError, adInfo: LevelPlayAdInfo) {} override fun onAdClicked(adInfo: LevelPlayAdInfo) {} override fun onAdClosed(adInfo: LevelPlayAdInfo) {} } ``` -------------------------------- ### Check Ad Readiness and Placement Capping Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Before showing an ad, verify that it is ready and that the placement is not capped. This prevents show failures and ensures ads are displayed correctly according to configured limits. ```java // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { mInterstitialAd.showAd(this, placementName); } ``` ```kotlin // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { mInterstitialAd.showAd(this, placementName) } ``` ```java public void showInterstitialAdWithPlacement() { // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { // Show ad with placement mInterstitialAd.showAd(this, placementName); } } ``` ```kotlin fun showInterstitialAdWithPlacement(placementName: String) { // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { // Show ad with placement mInterstitialAd.showAd(this, placementName) } } ``` -------------------------------- ### Java Interstitial Ad Implementation Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration This Java code demonstrates the full implementation of interstitial ads, including creating the ad instance, setting the listener, loading ads, and showing ads with or without a placement name. It also includes the necessary listener methods for ad events. ```java public class InterstitialAdActivity extends Activity implements LevelPlayInterstitialAdListener { private LevelPlayInterstitialAd mInterstitialAd; void createInterstitialAd() { mInterstitialAd = new LevelPlayInterstitialAd("adUnitId"); mInterstitialAd.setListener(this); } void loadInterstitialAd() { // Used to load or reload the ad mInterstitialAd.loadAd(); } void showInterstitialAd() { if (mInterstitialAd.isAdReady()) { mInterstitialAd.showAd(this); } } void showInterstitialAd(@NonNull String placementName) { // Check that ad is ready and that the placement is not capped if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) { mInterstitialAd.showAd(this, placementName); } } // LevelPlayInterstitialAdListener methods @Override public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdLoadFailed(@NonNull LevelPlayAdError error) {} @Override public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {} } ``` -------------------------------- ### Load Interstitial Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Use the `loadAd()` method to initiate the loading of an interstitial ad. This is the first step before an ad can be displayed. ```java mInterstitialAd.loadAd(); ``` ```kotlin mInterstitialAd.loadAd() ``` -------------------------------- ### Serve Interstitial Ad Unit Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration-checklist Serve the Interstitial ad to users once it's ready. The `onInterstitialReady` callback signals availability. Use `IronSource.showInterstitial(placementName)` to display the ad. Leave `placementName` empty for the default placement. ```java IronSource.showInterstitial(placementName); ``` -------------------------------- ### Create Interstitial Ad Object (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Instantiate a reusable LevelPlayInterstitialAd object for a given ad unit ID. This object can be used for multiple ad loads and shows throughout the app session. Ensure this is done after the onInitSuccess callback. ```kotlin val mInterstitialAd = LevelPlayInterstitialAd("adUnitId") ``` -------------------------------- ### Set Interstitial Listener (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Implement the LevelPlayInterstitialAdListener to receive callbacks for ad events such as loading success/failure, display, clicks, and closure. It's recommended to set the listener before loading the ad, and each ad should have its own listener. Callbacks are executed on the main thread. ```kotlin // Create the interstitial ad object val mInterstitialAd = LevelPlayInterstitialAd("adUnitId") mInterstitialAd.setListener(object : LevelPlayInterstitialAdListener { override fun onAdLoaded(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was loaded successfully } override fun onAdLoadFailed(levelPlayAdError: LevelPlayAdError) { // Ad load failed } override fun onAdDisplayed(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was displayed and visible on screen } override fun onAdDisplayFailed(levelPlayAdError: LevelPlayAdError, levelPlayAdInfo: LevelPlayAdInfo) { // Ad fails to be displayed // Optional } override fun onAdClicked(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was clicked // Optional } override fun onAdClosed(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was closed // Optional } override fun onAdInfoChanged(levelPlayAdInfo: LevelPlayAdInfo) { // Called after the ad info is updated. Available when another interstitial ad has loaded, and includes a higher CPM/Rate // Optional } }) ``` -------------------------------- ### Create Interstitial Ad Object (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Instantiate a reusable LevelPlayInterstitialAd object for a given ad unit ID. This object can be used for multiple ad loads and shows throughout the app session. Ensure this is done after the onInitSuccess callback. ```java LevelPlayInterstitialAd mInterstitialAd = new LevelPlayInterstitialAd("adUnitId"); ``` -------------------------------- ### Set Interstitial Listener (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Implement the LevelPlayInterstitialAdListener to receive callbacks for ad events such as loading success/failure, display, clicks, and closure. It's recommended to set the listener before loading the ad, and each ad should have its own listener. Callbacks are executed on the main thread. ```java // Create the interstitial ad object LevelPlayInterstitialAd mInterstitialAd = new LevelPlayInterstitialAd("adUnitId"); mInterstitialAd.setListener(new LevelPlayInterstitialAdListener() { @Override public void onAdLoaded(LevelPlayAdInfo levelPlayAdInfo) { // Ad was loaded successfully } @Override public void onAdLoadFailed(LevelPlayAdError levelPlayAdError) { // Ad load failed } @Override public void onAdDisplayed(LevelPlayAdInfo levelPlayAdInfo) { // Ad was displayed and visible on screen } @Override public void onAdDisplayFailed(LevelPlayAdError levelPlayAdError, LevelPlayAdInfo levelPlayAdInfo) { // Ad fails to be displayed // Optional } @Override public void onAdClicked(LevelPlayAdInfo levelPlayAdInfo) { // Ad was clicked // Optional } @Override public void onAdClosed(LevelPlayAdInfo levelPlayAdInfo) { // Ad was closed // Optional } @Override public void onAdInfoChanged(LevelPlayAdInfo levelPlayAdInfo) { // Called after the ad info is updated. Available when another interstitial ad has loaded, and includes a higher CPM/Rate // Optional } }); ``` -------------------------------- ### Show Interstitial Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration Display a loaded interstitial ad to the user. Ensure the ad is ready before calling `showAd()`. It is required to pass the current Activity context. ```java public void showInterstitialAd() { // Check that ad is ready if (mInterstitialAd.isAdReady()) { // Show ad mInterstitialAd.showAd(this); } } ``` ```kotlin fun showInterstitialAd() { // Check that ad is ready if (mInterstitialAd.isAdReady()) { // Show ad mInterstitialAd.showAd(this) } } ``` -------------------------------- ### Load Interstitial Ad Unit Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/interstitial-integration-checklist Load the Interstitial ad unit. It's recommended to load it shortly before serving to ensure availability. Avoid making consecutive load requests in a short period. ```java IronSource.loadInterstitial(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.