Skip to main content

Rewarded Ads

Users can choose to interact with these ads in exchange for in-app rewards, such as bonus points or extra lives in a game.

Introduction

Rewarded ads are usually displayed on the game page of the App. You will get corresponding rewards after playing the full-screen ad. You can refer to the ad source Hisavana, the effect is as follows:

Full screen image

Load Ads

Please set the corresponding parameters and listening callbacks.

Strongly recommended: During ad display, avoid using the same ad object to repeatedly initiate ad requests. If you need to initiate a new ad request, create a new ad object. Otherwise, the ad request will be invalid and an error message will be returned through the onError callback.

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

// Ad listener, listens for callbacks of ad loading completion (filling), display, click, exception, closing, and incentive actions
private static class TAdAlliance extends TAdListener {

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

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

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

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

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

// Display failure callback (applicable ad slots: all ad slots)
@Override
public void onShowError(TAdErrorCode errorCode) {
// Ad show failed callback
}

// Incentive callback (applicable ad slots: Reward)
@Override
public void onRewarded() {
// Ad rewarded callback
}
}

Reminder: source represents the advertising source, please refer to Ads Serial Table; For example: this time the advertisement is filled with pangle ads, then source=6.

Display Ads

Please show rewarded ads.

// Show rewarded ads
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity);
}
/**
* Optional
* For applications that need to count the arrival of advertising scenes, you can set the scene value yourself
* The main purpose is to count the utilization rate of the current advertising scene. The first parameter is the customized scene name, and the second parameter is the number of advertisements.
*/
String sceneToken = tRewardedAd.enterScene("rewarded_ad_scene_name", 1);
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity, sceneToken);
}

Destroy Ads

After exiting the advertising scene, please destroy the advertising object.

@Override
protected void onDestroy() {
super.onDestroy();
if (tRewardedAd != null) {
tRewardedAd.destroy();
}
}

Reminder: Please refer to Mediation Support for rewarded ads access, otherwise exceptions will occur.

Other APIs

API callIntroduce
tRewardedAd.hasAd()Are there any ads currently available