Skip to content

Rewarded Ads

Rewarded ads are advertisements that users can choose to watch in exchange for a reward, such as in-app currency, extra lives, or premium content. They are typically offered at natural points in an app, like after completing a level or task, allowing users to earn benefits while engaging with the ad.

Example

To create a rewarded ad, start by initializing a BoldwinRewarded with the following parameters:

  • placementID - A string used to identify the ad placement
  • adSizes - A list of BoldwinAdSize objects that specify the ad sizes
  • adListener - A BoldwinRewardedListener object that receives callbacks when the ad is loaded, shown, or closed
    private var adUnit: BoldwinRewarded? = null

    private fun createAd() {
        // 1. Create BoldwinRewarded
        adUnit = BoldwinRewarded(PLACEMENT_ID, this)

        // 2. Configure ad unit
        adUnit?.setAdSizes(BoldwinAdSize(320, 480))
        adUnit?.setAdListener(createListener())

        // 3. Load ad
        adUnit?.loadAd()
    }

    private fun createListener(): BoldwinRewardedListener = object : BoldwinRewardedListener {
        override fun onAdLoaded(ad: BoldwinAd?) {
            Log.d(TAG, "Ad loaded: $ad")
            // 4. Show ad
            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")
        }

        override fun onUserEarnedReward(reward: BoldwinReward?) {
            Log.d(TAG, "User earned reward: $reward")
        }
    }

The constructor of BoldwinRewarded 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:

    rewarded.setAdSizes(BoldwinAdSize(320, 480), BoldwinAdSize(300, 250))

If ad sizes are not specified, the SDK automatically determines the optimal ad sizes for the device.