Menu

Splash Ad

1. Implementation of Splash Ad Abstract Methods and Ad Event Callbacks

Method Parameters Return Value Description Required
show Activity activity: Activity ViewGroup container: Container of ad void Show splash ad Yes

CustomSplashAdapter provides an ad load timeout member variable, i.e., the fetchAdTimeout variable passed by the developer through the ATSplashAd constructor. This variable can be used to set the timeout for the ad platform.

1.2 Splash Ad Event Callbacks

Use the CustomSplashEventListener member variable of CustomSplashAdapter to implement ad event callbacks.

Callback Method Parameter Description Description
onSplashAdClicked - Callback to the developer when the ad is clicked.
onSplashAdShow - Callback to the developer when the ad is displayed.
onSplashAdDismiss - Callback to the developer when the ad is closed.

Note: When using the member variable CustomSplashEventListener, null-check handling is required, because the Mediation SDK may internally reclaim this Listener object.

1.3 Sample Code

java Copy
public class PangleSplashAdapter extends CustomSplashAdapter implements TTSplashAd.AdInteractionListener {
    private final String TAG = getClass().getSimpleName();

    String appId = "";
    String slotId = "";
    String personalizedTemplate = "";

    TTSplashAd splashAd;

    @Override
    public void loadCustomNetworkAd(final Context context, Map<String, Object> serverExtra, final Map<String, Object> localExtra) {
        if (serverExtra.containsKey("app_id") && serverExtra.containsKey("slot_id")) {
            appId = (String) serverExtra.get("app_id");
            slotId = (String) serverExtra.get("slot_id");

        } else {
            if (mLoadListener != null) {
                mLoadListener.onAdLoadError("", "app_id or slot_id is empty!");
            }
            return;
        }

        personalizedTemplate = "0";
        if (serverExtra.containsKey("personalized_template")) {
            personalizedTemplate = (String) serverExtra.get("personalized_template");
        }

        PangleInitManager.getInstance().initSDK(context, serverExtra, true, new PangleInitManager.InitCallback() {
            @Override
            public void onFinish() {
                startLoad(context, localExtra);
            }
        });
    }

    private void startLoad(Context context, Map<String, Object> localExtra) {
        TTAdManager ttAdManager = TTAdSdk.getAdManager();

        final TTAdNative mTTAdNative = ttAdManager.createAdNative(context);//baseContext is recommended for activity
        final AdSlot.Builder adSlotBuilder = new AdSlot.Builder().setCodeId(slotId);

        int width = 0;
        int height = 0;
        try {
            if (localExtra.containsKey(ATAdConst.KEY.AD_WIDTH)) {
                width = Integer.parseInt(localExtra.get(ATAdConst.KEY.AD_WIDTH).toString());
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        try {
            if (localExtra.containsKey(ATAdConst.KEY.AD_HEIGHT)) {
                height = Integer.parseInt(localExtra.get(ATAdConst.KEY.AD_HEIGHT).toString());
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        adSlotBuilder.setImageAcceptedSize(width, height); //Must be set

        if (TextUtils.equals("1", personalizedTemplate)) {// Native Express
            adSlotBuilder.setExpressViewAcceptedSize(width, height);
        }

        postOnMainThread(new Runnable() {
            @Override
            public void run() {
                AdSlot adSlot = adSlotBuilder.build();
                mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
                    @Override
                    public void onError(int i, String s) {
                        if (mLoadListener != null) {
                            mLoadListener.onAdLoadError(i + "", s);
                        }
                    }

                    @Override
                    public void onTimeout() {
                        if (mLoadListener != null) {
                            mLoadListener.onAdLoadError("", "onTimeout");
                        }
                    }

                    @Override
                    public void onSplashAdLoad(TTSplashAd ttSplashAd) {
                        splashAd = ttSplashAd;
                        if (mLoadListener != null) {
                            mLoadListener.onAdCacheLoaded();
                        }
                    }
                }, mFetchAdTimeout);
            }
        });

    }

    @Override
    public boolean isAdReady() {
        return splashAd != null;
    }

    @Override
    public void show(Activity activity, ViewGroup container) {
        if (splashAd != null) {
            splashAd.setSplashInteractionListener(PangleSplashAdapter.this);
            View splashView = splashAd.getSplashView();
            if (splashView != null) {
                container.addView(splashView);
            }
        }
    }

    @Override
    public String getNetworkName() {
        return PangleInitManager.getInstance().getNetworkName();
    }

    @Override
    public void destory() {

    }

    @Override
    public String getNetworkPlacementId() {
        return slotId;
    }

    @Override
    public String getNetworkSDKVersion() {
        return PangleInitManager.getInstance().getNetworkVersion();
    }

    @Override
    public void onAdClicked(View view, int i) {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdClicked();
        }

    }

    @Override
    public void onAdShow(View view, int i) {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdShow();
        }

    }

    @Override
    public void onAdSkip() {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdDismiss();
        }
    }

    @Override
    public void onAdTimeOver() {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdDismiss();
        }
    }

}
Previous
Rewarded Video
Next
Resume Installation
Last modified: 2026-07-08Powered by