Skip to content

Rewarded

Rewarded ads (also known as rewarded video ads) are a fullscreen format, but unlike interstitials the user is incentivized to watch its entire duration (usually 30 seconds) in order to get an in-app reward, such as in-game currency, extra lives or hints to pass a level.

The onEarnedReward callback will be triggered by the adapted network, signaling that you can give the user their reward. If the user decides to skip the ad, this callback will not be called.

Start loading an ad

XMediatorAds.startWith(
    activity = activity,
    appKey = appKey,
    initCallback = {
        XMediatorAds.Rewarded.load(REWARDED_PLACEMENT_ID)
    }
)
XMediatorAds.startWith(activity, APP_KEY, initResult -> {
    Log.d("InitResult", initResult.toString());
    XMediatorAds.getRewarded().load(REWARDED_PLACEMENT_ID);
    return null;
});

Showing an ad

Calling isReady() will return if there's a rewarded ad available to be shown, regardless of its placement id. If multiple ads with different placement ids were previously loaded, the SDK will try to show the best one available.

if (XMediatorAds.Rewarded.isReady()) {
    activity.runOnUiThread {
        XMediatorAds.Rewarded.show(activity, "rewarded-ad-space")
    }
}
if (XMediatorAds.getRewarded().isReady()) {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            XMediatorAds.getRewarded().show(activity, "rewarded-ad-space");
        }
    });
}

Showing an ad with placementId

When the app needs to present an ad for a specific placement id, isReady(placementId) and show(placementId) can be alternatively used.

if (XMediatorAds.Rewarded.isReady(REWARDED_PLACEMENT_ID)) {
    activity.runOnUiThread {
        XMediatorAds.Rewarded.show(REWARDED_PLACEMENT_ID, activity, "rewarded-ad-space")
    }
}
if (XMediatorAds.getRewarded().isReady(REWARDED_PLACEMENT_ID)) {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            XMediatorAds.getRewarded().show(REWARDED_PLACEMENT_ID, activity, "rewarded-ad-space");
        }
    });
}

Built-in features

Auto loading

Dismissed or failed to show ads will automatically trigger a new load request.

Auto retry

Failed to load ads will make a retry attempts, with an exponential backoff.

Additional settings

Register ad callbacks

Every ad callback indicates the placement id of the rewarded ad that triggered the event.

val rewardedListener = object : RewardedAds.Listener {
    override fun onEarnedReward(placementId: String) {
        Log.d("Presenter", "Rewarded earned for placementId: $placementId")
    }

    override fun onLoaded(placementId: String, loadResult: LoadResult) {
        Log.d("Presenter", "Rewarded loaded. Placement $placementId, result: $loadResult")
    }

    override fun onShowed(placementId: String) {
        Log.d("Presenter", "Rewarded shown: $placementId.")
    }

    override fun onFailedToShow(placementId: String, showError: ShowError) {
        // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
        Log.d("Presenter", "Rewarded failed to show, $placementId: ${showError.message}")
    }

    override fun onDismissed(placementId: String) {
        // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
        Log.d("Presenter", "Rewarded dismissed for placementId: $placementId")
    }

    override fun onImpression(placementId: String, impressionData: ImpressionData) {
        Log.d("Presenter", "Rewarded impression for placementId: $placementId, data: $impressionData")
    }

    override fun onClicked(placementId: String) {
        Log.d("Presenter", "Rewarded clicked for placementId: $placementId")
    }
}
XMediatorAds.Rewarded.addListener(listener = rewardedListener)
XMediatorAds.getRewarded().addListener(new RewardedAds.Listener() {
        @Override
        public void onEarnedReward(@NonNull String placementId) {
            Log.d("Presenter", "Rewarded earned. Placement " + placementId);
        }

        @Override
        public void onLoaded(@NonNull String placementId, @NonNull LoadResult loadResult) {
            Log.d("Presenter", "Interstitial loaded. Placement" + placementId + ", result: " + loadResult);
        }

        @Override
        public void onShowed(@NonNull String placementId) {
            Log.d("Presenter", "Interstitial shown. Placement " + placementId);
        }

        @Override
        public void onFailedToShow(@NonNull String placementId, @NonNull ShowError showError) {
            // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
            Log.d("Presenter", "Interstitial shown. Placement " + placementId + " error: " + showError);
        }

        @Override
        public void onDismissed(@NonNull String placementId) {
            // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
            Log.d("Presenter", "Interstitial onDismissed. Placement " + placementId);
        }

        @Override
        public void onImpression(@NonNull String placementId, @NonNull ImpressionData impressionData) {
            Log.d("Presenter", "Interstitial onImpression. Placement " + placementId + " ecpm: " + impressionData.getEcpm());
        }

        @Override
        public void onClicked(@NonNull String placementId) {
            Log.d("Presenter", "Interstitial onClicked. Placement " + placementId);
        }
    });

Advanced use cases

This guide provides the recommended integration steps to show a rewarded ad using X3M, which covers most of the common scenarios. For advanced use cases, where manually handling the lifecycle of the ad object is needed, refer to this section.

Code example

RewardedSample.kt
class RewardedSample : Activity() {
    private val appKey = "app_key"
    private val rewardedPlacementId = "placement_id"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_interstitial)
        XMediatorAds.Rewarded.addListener(listener = rewardedListener)
        findViewById<Button>(R.id.button_load).setOnClickListener {
            XMediatorAds.startWith(
                activity = this,
                appKey = appKey,
                initCallback = {
                    XMediatorAds.Rewarded.load(rewardedPlacementId)
                }
            )
        }
        findViewById<Button>(R.id.button_show).setOnClickListener {
            if(XMediatorAds.Rewarded.isReady(rewardedPlacementId)){
                this.runOnUiThread {
                    XMediatorAds.Rewarded.show(this)
                }
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        XMediatorAds.Rewarded.removeListener(listener = rewardedListener)
    }

    private val rewardedListener = object : RewardedAds.Listener {
        override fun onEarnedReward(placementId: String) {
            Log.d("SimplifyPresenter", "Rewarded earned for placementId: $placementId")
        }

        override fun onLoaded(placementId: String, loadResult: LoadResult) {
            Log.d("SimplifyPresenter", "Rewarded loaded. Placement $placementId, result: $loadResult")
        }

        override fun onShowed(placementId: String) {
            Log.d("SimplifyPresenter", "Rewarded shown: $placementId.")
        }

        override fun onFailedToShow(placementId: String, showError: ShowError) {
            // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
            Log.d("SimplifyPresenter", "Rewarded failed to show, $placementId: ${showError.message}")
        }

        override fun onDismissed(placementId: String) {
            // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
            Log.d("SimplifyPresenter", "Rewarded dismissed for placementId: $placementId")
        }

        override fun onImpression(placementId: String, impressionData: ImpressionData) {
            Log.d("SimplifyPresenter", "Rewarded impression for placementId: $placementId, data: $impressionData")
        }

        override fun onClicked(placementId: String) {
            Log.d("SimplifyPresenter", "Rewarded clicked for placementId: $placementId")
        }
    }
}