Skip to main content

Rewarded Video

Step 1.Prerequisites#

This document mainly introduces how to integrate Rewarded Ads :

  • Use Android Studio 3.2 or later
  • minSdkVersion 16 or later
  • compileSdkVersion 28 or later
  • Recommended: Create your TradPlus Apps and get your AppId
  • Initialize the TradPlus SDK for Android

Step 2.Integration#

1.Create and Cache the Rewarded Ad#

(1)V6.X New API#

/**
* @param context activity or application context
* @param AdUnitId create adUnit Id from your App
* @param Autostitial Ads show an ad automatically between activities,pass true to set auto load Mode.
*/
TPReward mTpReward = new TPReward(context, "AdUnitId", true);

(2)V5.X Old API#

/**
* @param context activity or application context
* @param adUnitId create adUnit Id from your App
* @param auto-loading mode Ads show an ad automatically between activities,pass true to set auto load Mode.
*/
TradPlusInterstitialExt mTradPlusInterstitial = new TradPlusInterstitialExt(context, "AdUnitId",true);
  • Using auto-loading mode, you can initialize the UnitId directly
mTradPlusInterstitial.initUnitId();
  • Don't use auto-loading mode
mTradPlusInterstitial.setCanLoadListener(new CanLoadListener() {
@Override
public void canLoad() {
//The first load the ad needs to be requested in the CanLoad() callback
mTradPlusInterstitial.load();
}
});
mTradPlusInterstitial.initUnitId();

2.Implement Event Listeners#

(1)V6.X New API#

//Basic Event Listeners
mTpReward.setAdListener(new RewardAdListener() {
@Override
public void onAdLoaded(TPAdInfo tpAdInfo) {
// Called when an ad is loaded after 'LoadAd'.
}
@Override
public void onAdClicked(TPAdInfo tpAdInfo) {
// Called when a rewarded ad is clicked.
}
@Override
public void onAdImpression(TPAdInfo tpAdInfo) {
// Called when a rewarded ad starts playing.
}
@Override
public void onAdFailed(TPAdError tpAdError) {
// Called when an ad is failed after 'LoadAd'.
}
@Override
public void onAdClosed(TPAdInfo tpAdInfo) {
// Called when a rewarded ad is closed.
}
@Override
public void onAdReward(TPAdInfo tpAdInfo) {
// Called when a rewarded ad is completed and the user should be rewarded.
}
});
//Advanced Event Listeners
mTpReward.setAllAdLoadListener(new LoadAdEveryLayerListener() {
@Override
public void onAdAllLoaded(boolean b) {
// Called when the adUnitId finish loading
}
@Override
public void oneLayerLoadFailed(TPAdError tpAdError, TPAdInfo tpAdInfo) {
// Called when the ad fails to load for the given adUnitId.
}
@Override
public void oneLayerLoaded(TPAdInfo tpAdInfo) {
// Called when every successfully loaded ad for the given adUnitId.
}
});

(2)V5.X Old API#

// Basic Event Listeners
// This listener must be called , for each ad network will callback
mTradPlusInterstitial.setInterstitialAdListener(new TradPlusInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoad(TradPlusInterstitial interstitial) {}
@Override
public void onInterstitialLoaded(TradPlusInterstitial tradPlusInterstitial) {
// Called when every successfully loaded ad for the given adUnitId.
}
@Override
public void onInterstitialFailed(TradPlusInterstitial tradPlusInterstitial, final TradPlusErrorCode tradPlusErrorCode) {
// Called when the ad fails to load for the given adUnitId.
if (tradPlusErrorCode != null) {
String code = tradPlusErrorCode.getCode();
String errormessage = tradPlusErrorCode.getErrormessage();
}
}
@Override
public void onInterstitialShown(TradPlusInterstitial tradPlusInterstitial) {
// Called when a rewarded ad starts playing.
}
@Override
public void onInterstitialClicked(TradPlusInterstitial tradPlusInterstitial) {
// Called when a rewarded ad is clicked.
}
@Override
public void onInterstitialDismissed(TradPlusInterstitial tradPlusInterstitial) {
// Called when a rewarded ad is closed.
// You need to call load() to reload the ad,if you don't use auto-loading mode.
//mTradPlusInterstitial.load();
}
@Override
public void onInterstitialRewarded(TradPlusInterstitial tradPlusInterstitial, final String currencyName, final int amount) {
// Called when a rewarded ad is completed and the user should be rewarded.
}
});
//This listener will returns a status to the results of the entire Ad load
mTradPlusInterstitial.setOnAllInterstatitialLoadedStatusListener(new OnAllInterstatitialLoadedStatusListener() {
@Override
public void onLoadStatus(boolean isLoadedSuccess, String unitId) {
//isLoadedSuccess == false,no ad network has been loaded successfully,
//isLoadedSuccess == true,you have available ads.
}
});

3.Load an Ad#

(1)V6.X New API#

mTpReward.loadAd();

(2)V5.X Old API#

mTradPlusInterstitial.load();

4.Set the SceneId#

(1)V6.X New API#

mTpReward.entryAdScenario("sceneId");
// Or you don't use sceneId
mTpReward.entryAdScenario("");

(2)V5.X Old API#

mTradPlusInterstitial.entryAdScenario("sceneId");
// Or you don't use sceneId
mTradPlusInterstitial.entryAdScenario();

Learn more about SceneId

You can create SceneId , as shown below :

You can get SceneId , as shown below :

5.Show an Ad#

If you choose to call SceneId when entering the interface where the ad slot is located, you must pass it while showing the ad, otherwise you only need to pass in the AdUnitId as a parameter

(1)V6.X New API#

mTpReward.showAd(Activity context,"sceneId");
//pass empty string
mTpReward.showAd(Activity context,"");

(2)V5.X Old API#

mTradPlusInterstitial.show("sceneId");
mTradPlusInterstitial.show();

6. Check is Ready#

Before show an Ad , using the isReady() method to make sure you have available ads.

(1)V6.X New API#

mTpReward.isReady();

(2)V5.X Old API#

//Reload ad when isReady() is false
//If you use auto-loading mode,the ad will be loaded automatically.
mTradPlusInterstitial.isReady();

7.Other API#

TPAdInfo is the information object of the ad,mainly including the id information of the third-party network platform.

MethodDescription
tpAdInfo.isoCodeIso Code
tpAdInfo.adSourceNameThird-party network name
tpAdInfo.adSourceIdThird-party network placement
tpAdInfo.loadTimeLoading time
tpAdInfo.ecpmGet ecpm
tpAdInfo.adUnitIdTradPlus adUnitId