Interstitial Ads
Interstitial ads are full-screen advertisements that appear at natural transition points in an app, such as between levels or screens.
Example
To create an interstitial ad, start by initializing a BoldwinInterstitial with the following parameters:
- placementId - A string used to identify the ad placement
- adSizes - A list of
BoldwinAdSizeobjects that specify the ad sizes - adListener - A
BoldwinInterstitialListenerobject that receives callbacks when the ad is loaded, shown, or closed
private var interstitial: BoldwinInterstitial? = null
private fun createAd() {
// 1. Create BoldwinInterstitial
interstitial = BoldwinInterstitial(PLACEMENT_ID, this)
// 2. Configure listener
interstitial?.setAdSizes(BoldwinAdSize(320, 480))
interstitial?.setAdListener(createListener())
// 3. Load ad
interstitial?.loadAd()
}
private fun createListener(): BoldwinInterstitialListener = object : BoldwinInterstitialListener {
override fun onAdLoaded(ad: BoldwinAd?) {
Log.d(TAG, "Ad loaded: $ad")
// 4. Show ad
interstitial?.show()
}
override fun onAdFailed(error: BoldwinError?) {
Log.e(TAG, "Ad failed to load: ${error?.message}")
}
override fun onAdOpened() {
Log.d(TAG, "Ad opened")
}
override fun onAdClicked() {
Log.d(TAG, "Ad clicked")
}
override fun onAdClosed() {
Log.d(TAG, "Ad closed")
}
}
The constructor of BoldwinInterstitial accepts a string that identifies the ad placement.
The loadAd() method loads the ad from the server. When the ad is loaded (after the onAdLoaded() callback), you can show it at any time by calling show(). You can also call it immediately after the onAdLoaded() callback.
Configuration
A single ad unit can be configured to support multiple ad sizes:
If ad sizes are not specified, the SDK automatically determines the optimal ad sizes for the device.