Menu

Splash Ads

💡Tips

  • To implement a custom Splash Ad Adapter, you need to extendcom.anythink.splash.unitgroup.api.CustomSplashAdapterand override all abstract methods. In the respective methods, you should call the ad platform's API and use the class member variable mLoadListener to callback the result of the ad loading, and use mImpressionListener to callback the results of ad display, clicks, and closings.

 

1. Additional Abstract Methods for Splash Ads Implementation

Method Description
void loadCustomNetworkAd(Context context, Map serverExtra, Map localExtra) Implement the ad loading logic for the custom network
context: The context passed to ATReward, VideoAd, ATInterstitial, ATNative, ATBannerView, ATSplashAd (Note: For splash ads, the context type is Activity).
serverExtra: Custom parameters configured on the server. Key-value pairs from the JSON string configured in the TopOn backend can be retrieved through the serverExtra parameter.
localExtra: Custom parameters passed during this load, available through the localExtra parameter which includes key-value pairs passed via ATSplashAd#setLocalExtra().
void show(Activity activity, ViewGroup container) For displaying ads
Container: The container for displaying ads

⚠️Note: The CustomSplashAdapter provides a member variable for the ad loading timeout, which can be passed in through the fetchAdTimeout variable in the ATSplashAd constructor. This variable can be used to set the timeout for the ad platform.

 

2. Splash Ads Event Callbacks

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

Method Description
void onSplashAdClicked() Called when the ad is clicked
void onSplashAdShow() Called when the ad is displayed
void onSplashAdDismiss() Called when the ad is closed

⚠️Note: When using the  CustomSplashEventListener  member variable, ensure to handle null checks.

 

3. Sample code 

public class PangleSplashAdapter extends CustomSplashAdapter implements TTSplashAd.AdInteractionListener {
    
    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);
        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);

        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
Native Ads
Next
Customize Client Bidding Network
Last modified: 2025-05-30Powered by