Skip to main content

NativeBanner

Step 1.Prerequisites#

This document mainly introduces how to integrate nativebanner 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/ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>

(2)V5.X Old API#

<com.tradplus.ads.mobileads.TradPlusView
android:id="@+id/native_banner"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true">
</com.tradplus.ads.mobileads.TradPlusView>

2.2 Create an Ad#

(1)V6.X New API#

TPNativeBanner tpNativeBanner;
ViewGroup adContainer;
//Create adUnit Id from your App
adContainer = findViewById(R.id.ad_container);
tpNativeBanner = new TPNativeBanner(context);

(2)V5.X Old API#

TradPlusView nativeViewBanner;
nativeViewBanner = findViewById(R.id.native_banner);
nativeViewBanner.setAdUnitId("AdUnitId");
//Set the layout of the ad, the xml file is obtained from the Demo or Download SDK file
nativeViewBanner.setAdLayoutName("native_ad_list_item","video_ad_list_item","native_banner_ad_unit");

2.3 Implement Event Listeners#

(1)V6.X New API#

tpNativeBanner.setAdListener(new BannerAdListener() {
@Override
public void onAdClicked(TPAdInfo tpAdInfo) {
// Called when a nativebanner ad is clicked.
}
@Override
public void onAdImpression(TPAdInfo tpAdInfo) {
// Called when a nativebanner ad starts playing.
}
@Override
public void onAdLoaded(TPAdInfo tpAdInfo) {
// Called when the ad for the given adUnitId has loaded.
}
@Override
public void onAdLoadFailed(TPAdError error) {
// Called when the ad fails to load for the given adUnitId.
}
@Override
public void onAdClosed(TPAdInfo tpAdInfo) {
// Called when a nativebanner ad is closed.
}
});

(2)V5.X Old API#

nativeViewBanner.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 fails to load for the given adUnitId.
}
@Override
public void onAdViewClicked(TradPlusView tradPlusView) {
// Called when a nativebanner ad is clicked.
}
@Override
public void onAdViewExpanded(TradPlusView tradPlusView) {
// Called when a nativebanner ad starts playing.
}
@Override
public void onAdViewCollapsed(TradPlusView tradPlusView) {
}
@Override
public void onAdsSourceLoaded(Object o) {}
});

2.4 Load an Ad#

(1)V6.X New API#

adContainer.addView(tpNativeBanner);
//Create adUnit Id from your App
tpNativeBanner.loadAd("AdUnitId");

(2)V5.X Old API#

nativeViewBanner.loadAd();
  • How to create Add Unit , as shown below:

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

2.5 Release resources#

(1)V5.X Old API#

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