Interstitials
1、Load an ad
- Developers can preload ads before displaying them.
- To request a interstitial ad, you need to declare a TPInterstitial object first, set the listener and load the video creative.
TPInterstitial tpInterstitial = new TPInterstitial(activity,"AdUnitID");
tpInterstitial.setAdListener(new InterstitialAdListener());
tpInterstitial.loadAd();
2、Show interstitial 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.
if(tpInterstitial.isReady()) {
tpInterstitial.showAd(activity, null);
}
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.
tpInterstitial.setAdListener(new InterstitialAdListener() {
@Override // Callback when the first ad source is loaded successfully;A load will only be called back once
public void onAdLoaded(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad failed to load
public void onAdFailed(TPAdError error) {}
@Override // Interstitial ad closed
public void onAdClosed(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad played start(Some advertising platforms support)
public void onAdVideoStart(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad played completely(Some advertising platforms support)
public void onAdVideoEnd(TPAdInfo tpAdInfo) {}
@Override // Interstitial ad is shown failed(Some advertising platforms support)
public void onAdVideoError(TPAdInfo tpAdInfo, TPAdError error) {}
});
4、Code
- We recommend that you use the InterstitialActivity to understand the use of the SDK.