Rewarded Ads
Users can choose to interact with these ads in exchange for in-app rewards, such as extra points or lives in a game. Supported ad content includes images and video.
Overview
Rewarded ads are typically shown on game screens within the app. After watching the full-screen ad, the user receives a corresponding reward. Refer to the Hisavana SSP ad source for a sample preview:
| Full Screen |
|---|
![]() |
We recommend downloading and trying the Mediation Demo to get a more intuitive and in-depth understanding of the SDK's features and usage.
Load Ad
Set the required parameters and listener callbacks. Pay close attention to which ad unit types each callback applies to, to avoid integration errors.
Strongly recommended: Avoid making a new ad request using the same ad object while an ad is being displayed. If you need to make a new request, create a new ad object. Otherwise the request will be invalid and an error will be returned via the onError callback.
// Initialize the rewarded ad object; "rewarded_id" is the rewarded ad unit ID
TRewardedAd tRewardedAd = new TRewardedAd(this, "rewarded_id");
// Build the ad request body
TAdRequestBody tAdRequest = new TAdRequestBody.AdRequestBodyBuild()
.setAdListener(new TAdAlliance())
.build();
// Set the ad request body
tRewardedAd.setRequestBody(tAdRequest);
// Load the ad and return the optimal ad within the configured wait time
tRewardedAd.loadAd();
// Ad listener — callbacks for load, show, click, error, close, and reward events
private static class TAdAlliance extends TAdListener {
// Load callback (applicable to: all ad units)
@Override
public void onLoad() {
// Ad loaded callback
}
// Error callback (applicable to: all ad units)
@Override
public void onError(TAdErrorCode errorCode) {
// Ad failed callback
}
// Show callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onShow(int source) {
// Ad show callback
}
// Click callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onClicked(int source) {
// Ad click callback
}
// Close callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onClosed(int source) {
// Ad close callback
}
// Reward callback (applicable to: Reward)
@Override
public void onRewarded() {
// Rewarded playback completed
}
}
Reminder: source indicates the ad network. Refer to the Ad Source Correlation Table. For example, if the filled ad is from Pangle, then source = 6.
Show Ad
Display the rewarded ad.
// Show the rewarded ad
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity);
}
/**
* Optional
* For apps that need to track ad scene impressions, set the scene value here.
* The first parameter is a custom scene name; the second is the ad count.
*/
String sceneToken = tRewardedAd.enterScene("rewarded_ad_scene_name", 1);
if (tRewardedAd != null && tRewardedAd.hasAd()) {
tRewardedAd.show(activity, sceneToken);
}
Destroy Ad
Release ad resources promptly to prevent memory leaks.
// Destroy the ad object when leaving the ad scene.
@Override
protected void onDestroy() {
super.onDestroy();
if (tRewardedAd != null) {
tRewardedAd.destroy();
tRewardedAd = null;
}
}
Reminder: For rewarded ad integration, refer to Mediation Help to avoid errors.
Other APIs
| API | Description |
|---|---|
| tRewardedAd.hasAd() | Whether a ready ad is available |
