Rewarded

Integration

Just as interstitials, rewarded ads can only be integrated with code. Below we show a simple example to understand how it works:

class MainActivity : Activity() {

    private var interstitialAd: InterstitialAd? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        interstitialAd = InterstitialAd(this, "<Wortise Ad Unit ID>").also {
	        it.loadAd()
        }
    }
    
    override fun onDestroy() {
        ...
        interstitialAd?.destroy()
    }
    
    fun showInterstitial() {
        if (interstitialAd?.isAvailable == true) {
            interstitialAd?.showAd(this)
        }
    }
}

Listener configuration

Like occurs with other formats, a listener can be set to receive the events that happen during the rewarded lifecycle. For this, it is needed to implement the RewardedAd.Listener interface just as shown in the example below:

Última actualización