Integrate Interstitial Ads

To integrate any ad format, you must first have completed the instructions in the basic integration article.

Interstitial ads are full-screen ads that cover the interface of your app. They're typically displayed at natural transition points in the flow of your app, such as between activities or during the pause between levels in a game. Some interstitial ads are rewarded ads.

Create and Load an Interstitial Ad

KotlinJava
import com.vungle.ads.InterstitialAd
private var interstitialAd: InterstitialAd? = null
interstitialAd = InterstitialAd(requireContext(), placementId, AdConfig().apply {
}).apply {
 adListener = this@InterstitialFragment
 load()
}

Play an Interstitial Ad

  1. Once the interstitial ad is successfully loaded, you can display it by calling:

    KotlinJava
    if (interstitialAd?.canPlayAd() == true) {
     interstitialAd?.play()
    }
    
  2. During the time the interstitial ad is visible to the user, you can listen for ad lifecycle events through delegate callback methods (refer to the Register for Callbacks section below).
  3. The ad is closed when the user closes it. You do not need to add steps in your code to close it.

Register for Callbacks

To receive notifications for ad events, declare conformance to InterstitialAdListener protocol and implement callback methods.

KotlinJava
override fun onAdLoaded(baseAd: BaseAd) {
Log.d(TAG, "Creative id:" + baseAd.creativeId)
}


override fun onAdStart(baseAd: BaseAd) {
}


override fun onAdImpression(baseAd: BaseAd) {
}


override fun onAdEnd(baseAd: BaseAd) {
}


override fun onAdClicked(baseAd: BaseAd) {
}


override fun onAdLeftApplication(baseAd: BaseAd) {
}


override fun onAdFailedToLoad(baseAd: BaseAd, adError: VungleError) {
}


override fun onAdFailedToPlay(baseAd: BaseAd, adError: VungleError) {
}

The following table lists all the available AdConfig options:

Option Description
setAdOrientation
  • AdConfig.AUTO_ROTATE: Video ad will rotate to match device orientation
  • AdConfig.LANDSCAPE:
    Force video ad to play in landscape orientation
  • AdConfig.PORTRAIT: Force video ad to play in portrait orientation
setBackButtonImmediatelyEnabled Sets whether the Android back button will be immediately enabled during the video ad, or will be inactive until the on screen close button appears (this latter is the default).
setWatermark Add watermark for ads. Usually this method will be called by mediation.

Test an Interstitial Ad

You can test an Interstitial ad in one of two ways: by setting your app status to Test Mode so that Vungle can deliver test ads to your app, or by adding a test device to your app so that Vungle can deliver test ads specifically to the test device. Follow the instructions in Test Your Integration: Test Mode and Test Devices.

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?