Banners
1、Load an ad
- Developers can preload ads before displaying them.
- TpBanner is a ViewGroup, the size and position can be customized, developers need to add TpBanner to the specified position.
- Create an advertisement object TPBanner, some advertisement platforms require acitivity to be passed in, otherwise the advertisement cannot be loaded successfully
TPBanner tpBanner = new TPBanner(activity);
tpBanner.setAdListener(new BannerAdListener());
tpBanner.loadAd("AdUnitID");
// It is recommended to use FrameLayout. If you use LinearLayout, you need to set layoutParams while addView
adContainer.addView(tpBanner);
2、Show banner ad
- After the ad is loaded successfully, TP will add the ad directly to the TpBanner without calling the showAd() method;
3、Destroy an ad
- After the ad does not need to be displayed any more, you should destroy it:
tpBanner.onDestroy();
tpBanner = null;
4、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.
tpBanner.setAdListener(new BannerAdListener() {
@Override // Callback when the first ad source is loaded successfully;A load will only be called back once
public void onAdLoaded(TPAdInfo tpAdInfo) {}
@Override // Banner ad clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}
@Override // Banner ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}
@Override // Banner ad failed to load
public void onAdLoadFailed(TPAdError error) {}
@Override // Banner ad closed
public void onAdClosed(TPAdInfo tpAdInfo) {}
});
5、Code
- We recommend that you use the BannerActivity to understand the use of the SDK.