Skip to main content

Splash

Step 1.Prerequisites#

This document mainly introduces how to integrate Splash 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#

2.1 Add AdView to the layout#

Start by including this XML block to your Activity’s or Fragment’s layout.

(1)V6.X New API#

<FrameLayout
android:id="@+id/splash_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

(2)V5.X Old API#

<com.tradplus.ads.mobileads.TradPlusView
android:id="@+id/splash_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.tradplus.ads.mobileads.TradPlusView>

2.2 Create and Cache the Splash Ad#

(1)V6.X New API#

ViewGroup adContainer;
...
adContainer = findViewById(R.id.splash_container);
//Create adUnit Id from your App
TPSplash tpSplash = new TPSplash(context,"AdUnitId");

(2)V5.X Old API#

TradPlusView tradPlusView;
tradPlusView = findViewById(R.id.splash_view);
tradPlusView.setAdUnitId("AdUnitId");
//Must setAdSize
tradPlusView.setAdSize(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
//If Kuaishou is aggregated
//splash_view_ad_layout.xml
// the xml file is obtained from the Demo or Download SDK file
tradPlusView.setAdLayoutName("splash_view_ad_layout");
  • After Add Unit ,you can get adUnitId, as shown below:

2.3 Implement Event Listeners#

(1)V6.X New API#

tpSplash.setAdListener(new SplashAdListener() {
@Override
public void onAdClicked(TPAdInfo tpAdInfo) {
// Called when a splash ad is clicked.
}
@Override
public void onAdImpression(TPAdInfo tpAdInfo) {
// Called when a splash ad starts playing.
}
@Override
public void onAdClosed(TPAdInfo tpAdInfo) {
// Called when a splash ad is closed.
}
@Override
public void onAdLoaded(TPAdInfo tpAdInfo, TPBaseAd tpBaseAd) {
// Called when the ad for the given adUnitId has loaded.
}
@Override
public void onAdLoadFailed(TPAdError error) {
// Called when the ad for the given adUnitId has failed.
}
});

(2)V5.X Old API#

tradPlusView.setAdViewListener(new TradPlusView.FSAdViewListener() {
@Override
public void onAdViewLoaded(TradPlusView tradPlusView) {
// Called when the ad for the given adUnitId has loaded.
}
@Override
public void onAdViewFailed(TradPlusView tradPlusView, TradPlusErrorCode tradPlusErrorCode) {
// Called when the ad for the given adUnitId has failed.
}
@Override
public void onAdViewClicked(TradPlusView tradPlusView) {
// Called when a splash ad is clicked.
}
@Override
public void onAdViewExpanded(TradPlusView tradPlusView) {
// Called when a splash ad starts playing.
}
@Override
public void onAdViewCollapsed(TradPlusView tradPlusView) {}
@Override
public void onAdsSourceLoaded(Object o) {}
});
tradPlusView.setSplashAdViewListener(new TradPlusView.SplashAdViewListener() {
@Override
public void onADDismissed() {}
@Override
public void onADTick(long l) {}
});

2.4 Load an Splash Ad#

(1)V6.X New API#

//@param:ViewGroup
tpSplash.loadAd(adContainer);

(2)V5.X Old API#

tradPlusView.loadAd();

2.5 Release resources#

(1)V5.X Old API#

@Override
protected void onDestroy() {
mTradPlusView.destroy();
super.onDestroy();
}