Skip to main content

Rewarded Ads

Users can voluntarily choose to interact with these ads in exchange for in-app rewards, such as earning points or extra lives in games. Ad content supports images and videos.

Introduction

Rewarded ads are typically displayed on game pages within apps. Users watch full-screen ads to receive corresponding rewards. Refer to Hisavana ad source, effect as shown:

Full Screen

We recommend that you download and experience the Mediation Demo to gain a more intuitive and in-depth understanding of the SDK's features and usage. Through the Demo, you can quickly get started and explore its application in real-world scenarios.

Loading Ads

Please configure the corresponding parameters and callback listeners. Be sure to carefully review the documentation for the applicable ad placement types in relevant callbacks to avoid integration discrepancies.

Strongly Recommended: During ad display, avoid making repeated ad requests using the same ad object. If you need to make a new ad request, please create a new ad object. Otherwise, the ad request will be invalid and an error message will be returned via the onError callback.

// Initialize rewarded ad object, where "rewarded_id" is the rewarded ad unit ID
TRewardedAd tRewardedAd = new TRewardedAd(this, "rewarded_id");
// Build ad request body
TAdRequestBody tAdRequest = new TAdRequestBody.AdRequestBodyBuild()
.setAdListener(new TAdAlliance())
.build();
// Set ad request body
tRewardedAd.setRequestBody(tAdRequest);
// After loading ads, return the optimal ad callback within the set waiting time
tRewardedAd.loadAd();

// Ad listener, monitors ad load completion (fill), display, click, exception, close, reward actions callbacks
private static class TAdAlliance extends TAdListener {

// Load completion callback (applicable ad units: all ad units)
@Override
public void onLoad() {
// Ad loaded callback
}

// Exception callback (applicable ad units: all ad units)
@Override
public void onError(TAdErrorCode errorCode) {
// Ad failed callback
}

// Display callback (applicable ad units: Splash, Interstitial, Banner, Reward)
@Override
public void onShow(int source) {
// Ad show callback
}

// Click callback (applicable ad units: Splash, Interstitial, Banner, Reward)
@Override
public void onClicked(int source) {
// Ad click callback
}

// Close callback (applicable ad units: Splash, Interstitial, Banner, Reward)
@Override
public void onClosed(int source) {
// Ad close callback
}

// Reward callback (applicable ad units: Reward)
@Override
public void onRewarded() {
// Rewarded playback completed
}
}

Reminder: source represents the ad source, please refer to Ad Source Correlation Table; for example: if this ad fill display is pangle ad, then source=6.

Display Ads

Please display the rewarded ad.

// Display rewarded ad
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity);
}
/**
* Optional
* For applications that need to track ad scenario reach, you can set scenario values yourself
* Main purpose is to track current ad scenario utilization rate, first parameter custom scenario name, second parameter ad quantity
*/
String sceneToken = tRewardedAd.enterScene("rewarded_ad_scene_name", 1);
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity, sceneToken);
}

Destroy Ads

Please recycle ads promptly, otherwise the App may experience memory leaks.

// After exiting the ad scenario, please destroy the ad object.
@Override
protected void onDestroy() {
super.onDestroy();
if (tRewardedAd != null) {
tRewardedAd.destroy();
}
}

Reminder: For rewarded ad integration please refer to Mediation Help, otherwise it may cause exceptions.

Other APIs

API CallDescription
tRewardedAd.hasAd()Whether there is currently an available ad