Skip to main content

Native Ads

1、Load an ad#

  • Developers can preload ads before displaying them.
  • To request a native ad, you need to declare a TPNative object first, set the listener and load the native creative.
TPNative tpNative = new TPNative(activity,"AdUnitID");
tpNative.setAdListener(new NativeAdListener());
tpNative.loadAd();

2、Show native ad#

  • When the display opportunity arrives, check whether there is an available ad through the isReady() method; or monitor whether the ad is called back onAdLoaded.
  • AdContainer is the container for displaying ads.TP will add the loaded ad to the container.
  • layoutId is the layout file,The default layout file is provided in the TradPlusSDK download platform zip, the developer can change the layout style, but cannot change the android:id resource ID
tpNative.showAd(adContainer, layoutId);

3、Register Ad Event Callback#

  • Note: Don't perform the retry loading method ad in onAdFailed callback – it'll cause a lot of useless requests and could make your app run slowly.
tpNative.setAdListener(new NativeAdListener() {
@Override // Callback when the first ad source is loaded successfully;A load will only be called back once
public void onAdLoaded(TPAdInfo tpAdInfo, TPBaseAd tpBaseAd) {}
@Override // Native ad clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}
@Override // Native ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}
@Override // Native ad failed to load
public void onAdLoadFailed(TPAdError tpAdError) {}
@Override // Native ad is shown failed(Some advertising platforms support)
public void onAdShowFailed(TPAdError tpAdError, TPAdInfo tpAdInfo) {}
@Override // Native ad closed
public void onAdClosed(TPAdInfo tpAdInfo) {}
});

4、Code#

  • We recommend that you use the NativeActivity to understand the use of the SDK.