Rewarded Ads
1. Load an ad
-
Developers can preload ads before displaying them.
-
To request a rewarded video ad, you need to declare a
TPRewardobject first, set the listener, and load the ad creative.TPReward tpReward = new TPReward(activity, "AdUnitID");
tpReward.setAdListener(new RewardAdListener());
tpReward.loadAd();
2. Show reward video ad
-
It is recommended to use the
isReady()method to check if ads are ready; if it returns true, you can then display them.if (tpReward.isReady()) {
tpReward.showAd(activity, null);
}
3. Register Ad Event Callback
-
Note: Don't retry loading ads in the
onAdFailedcallback – it'll cause a lot of useless requests and could make your app run slowly.tpReward.setAdListener(new RewardAdListener() {
@Override
// Callback when the first ad source is loaded successfully; each load will only trigger the callback once
public void onAdLoaded(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad failed to load
public void onAdFailed(TPAdError error) {}
@Override
// Rewarded video ad closed
public void onAdClosed(TPAdInfo tpAdInfo) {}
@Override
// It's time to offer some reward to the user
public void onAdReward(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad playback started (supported by some advertising platforms)
public void onAdVideoStart(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad playback completed (supported by some advertising platforms)
public void onAdVideoEnd(TPAdInfo tpAdInfo) {}
@Override
// Rewarded video ad failed to show (supported by some advertising platforms)
public void onAdVideoError(TPAdInfo tpAdInfo, TPAdError error) {}
});
4. Code
- We recommend that you use the RewardedVideoActivity to understand the use of the SDK.