Skip to main content

NativeSlot

Step 1.Prerequisites#

This document mainly introduces how to integrate nativeslot Ads:

Step 2.Integration#

2.1 Create an TradPlusListNativeOption#

(1)V6.X New API#

/*
* @param:interval Represents the interval
* @param:maxLength Indicates the maximum number of rows that the current list can support
*/
TradPlusListNativeOption option = new TradPlusListNativeOption(6,50);

(2)V5.X Old API#

/*
* @param:interval Represents the interval
* @param:maxLength Indicates the maximum number of rows that the current list can support
*/
TradPlusListNativeOption option = new TradPlusListNativeOption(interval,maxLength);

2.2 Create an Ad#

(1)V6.X New API#

//Create adUnit Id from your App
TPNative tpNative = new TPNative(context, "AdUnitId");

(2)V5.X Old API#

TradPlusSlot tradPlusSlot = new TradPlusSlot.Builder()
.setUnitId("AdUnitId")
.setLayoutName("native_ad_list_item") // (Must) The xml file is obtained from the Demo or Download SDK file
.setLayoutNameEx("video_ad_list_item") // (Must)
.setLayoutBannerName("native_banner_ad_unit") //(Optional) Only you need NativeBanner type
.setAdCount(5) //(Must) Get the number of ads ,Get 5 ads every time
.build();
  • How to create Add Unit , as shown below:

  • After add Add Unit, you can get adUnitId, as shown below:

2.3 Load an Ad and Implement Event Listeners#

(1)V6.X New API#

tpNative.setAdListener(new NativeAdListener() {
@Override
public void onAdClicked(TPAdInfo tpAdInfo) { }
@Override
public void onAdImpression(TPAdInfo tpAdInfo) { }
@Override
public void onAdLoadFailed(TPAdError error) { }
@Override
public void onAdClosed(TPAdInfo tpAdInfo) { }
@Override
public void onAdLoaded(TPAdInfo tpAdInfo, TPBaseAd tpBaseAd) {
// Called when the ad for the given adUnitId has loaded.
// Get loaded Native ads
TPCustomNativeAd nativeAd = tpNative.getNativeAd();
//Add successful objects to your list
...
}
});
//Load ad
tpNative.loadAd();

(2)V5.X Old API#

TradPlusViewExt tradPlusViewExt = new TradPlusViewExt();
tradPlusViewExt.loadFeedAd(this,tradPlusSlot, new TradPlusViewExt.TradPlusFeedListener() {
@Override
public void onFeedAdLoad(List<TradPlusView> ads) {
// Called when the ad for the given adUnitId has loaded.
}
@Override
public void onClicked(String unitid, String networkName) {}
@Override
public void onError(TradPlusErrorCode errorCode) {}
@Override
public void onAdsSourceLoad(List<Object> adsSource) {}
});

2.4 Show an Ad#

(1)V6.X New API#

//@param:ViewGroup
//@param:layout,R.layout.native_ad_list_item you can get from Demo or download file
//@param:pass empty string
tpNativeAd.showAd(adContainer, R.layout.native_banner_ad_unit, "");
  • V5.X Old API After the ad is loaded successfully, it will be automatically populated into the layout

Demohttps://github.com/tradplus/Android