Search...
Menu

Customized Mediation Adapter

  1. Using Custom Mediation Platform

Please refer to the guide on how to set up a custom mediation platform in the TopOn Dashboard

(1) You only need to extend MCMediationAdapter and override the corresponding methods. None of the methods in the custom mediation platform Adapter need to be manually invoked—the MCSDK will automatically call these methods at appropriate times.

(2) When you call the MCSDK's load API to load ads, the loading results from the custom mediation platform must be communicated to the MCSDK by invoking the relevant event callbacks in MCAdapterListener. Ultimately, you will receive notifications from the MCSDK through success/failure callbacks.


  1. Public Abstract Methods

● MCMediationAdapter

Method Description
void initSDK(Context context, MCMediationInfo mediationInfo, MCAdapterInitListener initListener) Initializes the SDK for the custom mediation platform.
void setLogDebug(boolean isLogDebug) Enables/disables debug logs for the custom mediation platform.
String getSdkVersion() Retrieves the SDK version of the custom mediation platform.
void loadRewardedAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) Loads rewarded video ads for the custom mediation platform.
void loadInterstitialAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) Loads interstitial ads for the custom mediation platform.
void loadAdViewAd(Context context, MCLoadInfo loadInfo, MCBannerSize bannerSize, MCAdapterListener listener) Loads banner ads for the custom mediation platform.
void loadAppOpenAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) Loads app open ads for the custom mediation platform.
void loadNativeAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) Loads native ads for the custom mediation platform.
void show(Activity activity, ViewGroup container, Map<String, Object> extra, MCAdapterListener listener) Displays ads for the custom mediation platform.
view getBannerView() Retrieves the BannerView from the custom mediation platform.
boolean isAdReady() Checks if the ad is ready to be displayed.
void destroy() Releases resources for the custom mediation platform.

  1. Mediation Platform Information Object

● MCMediationInfo

Method Description
int getMediationId() Retrieves the ID of the mediation platform.
Map<String, Object> getInitParamsMap() Retrieves the initialization parameters (e.g., appId, appKey) required to initialize the mediation platform.
String getMediationAdapterClass() Retrieves the class name of the mediation platform Adapter.

  1. Ad Load Information Object

● MCLoadInfo

Method Description
Map<String, Object> getLoadExtraParameter() Retrieves the extra parameters map for ad loading.
void setLoadExtraParameter(Map<String, Object> loadExtraParameter) Sets platform-specific parameters required for ad loading.
String getPlacementId() Retrieves the ad placement ID of the mediation platform.
double getWeight() Retrieves the weight value of the mediation platform.
MediationUnitInfo getMediationUnitInfo() Retrieves the UnitInfo object of the mediation platform.
int getFetchTimeout() Retrieves the timeout duration for loading app open ads.
Map<String, Object> getServerMap() Retrieves parameters delivered by the server.

  1. Ad Load Event Callbacks

● MCAdapterListener

Method Description
void onAdLoadSuccess(IAdInfo adInfo) Notifies the MCSDK when an ad loads successfully (for rewarded, interstitial, banner, and app open ads). adInfo: The mediation platform's ad info object.
void onAdLoadSuccess(IAdInfo adInfo, MCNativeAd mcNativeAd) Notifies the MCSDK when a native ad loads successfully. adInfo: The mediation platform's ad info object. McNativeAd`: The native ad object.
void onAdLoadFail(MCAdapterError adapterError) Notifies the MCSDK when ad loading fails. adapterError: Error code object from the mediation platform.
void onAdShow(IAdInfo adInfo) Notifies the MCSDK when an ad is displayed successfully.
void onAdClick(IAdInfo adInfo) Notifies the MCSDK when an ad is clicked.
void onAdClose(IAdInfo adInfo) Notifies the MCSDK when an ad is closed.
void onAdVideoStart(IAdInfo adInfo) Notifies the MCSDK when an ad video starts playing.
void onAdVideoEnd(IAdInfo adInfo) Notifies the MCSDK when an ad video finishes playing.
void onAdDisplayFailed(IAdInfo adInfo, MCAdapterError adapterError) Notifies the MCSDK when ad display fails. adapterError: Error code object.
void onAdReward(IAdInfo adInfo, MCReward rewardInfo) Notifies the MCSDK when a reward is triggered (for rewarded ads). rewardInfo: Reward object.
void onAdRevenuePaid(IAdInfo adInfo) Notifies the MCSDK when ad revenue is captured.

  1. Ad Load Result Object

● IAdInfo

💡Tips

  • You must extend IAdInfo and construct the ad load result object based on the method descriptions below.
Method Description
String getMediationPlacementId() Returns the ad placement ID of the mediation platform.
String getScenarioId() Returns the scenario ID of the mediation platform.
String getNetworkPlacementId() Returns the ad platform's placement ID configured in the mediation platform.
MCAdFormat getFormat() Returns the ad format type: MCAdFormat.REWARDED (Rewarded Video) MCAdFormat.INTERSTITIAL (Interstitial) MCAdFormat.APP_OPEN (App Open) MCAdFormat.NATIVE (Native) MCAdFormat.BANNER (Banner).
double getRevenue() Returns the revenue generated from the ad impression.
String getRevenuePrecision() Returns revenue precision: IAdInfo.PRECISION_PUBLISHER_DEFINED (price defined in the mediation platform) IAdInfo.PRECISION_EXTRA (real-time bidding revenue) IAdInfo.PRECISION_ESTIMATED (estimated revenue).
String getCurrency() Returns the currency unit (e.g., CNY or USD).
String getCountry() Returns the country code (e.g., "CN").
String getNetworkFirmName() Returns the name of the ad platform.
Map<String, Object> getMediationExtraMap() Returns additional metadata from the mediation platform.
String getOriginJsonString() Returns the raw JSON response from the mediation platform.

  1. Example Code

java Copy
package com.company.adapter.YourCustomMCMediationAdapter;

import com.mcsdk.core.api.InitializationStatus;
import java.util.concurrent.atomic.AtomicBoolean;

public class YourCustomMCMediationAdapter extends MCMediationAdapter {

    static final AtomicBoolean initialized = new AtomicBoolean();
    static boolean hasInit;

    @Override
    public void initSDK(Context context, MCMediationInfo mediationInfo, MCAdapterInitListener initListener) {
        if (initialized.compareAndSet(false, true)) {
            Map&lt;String, Object&gt; initParamsMap = mediationInfo.getInitParamsMap();
            String appId = initParamsMap.get(&quot;app_id&quot;);
            String appKey = initParamsMap.get(&quot;app_key&quot;);
            YourAdSDK.initSDK(context, appId, appKey, new YourInitListener(){
                if (appId or appKey is null) {
                    initListener.onCompletion(InitializationStatus.INITIALIZED_FAILURE, &quot;appId or appKey is null&quot;);
                } else {
                    hasInit = true;
                    initListener.onCompletion(InitializationStatus.INITIALIZED_SUCCESS, &quot;init successed&quot;);
                }
            });
        }
        if (initListener != null) {
            if (hasInit) {
                initListener.onCompletion(InitializationStatus.INITIALIZED_SUCCESS, &quot;init successed&quot;);
            } else {
                initListener.onCompletion(InitializationStatus.INITIALIZING, &quot;init failed&quot;);
            }
        }
    }

    @Override
    public void setCustomMaps(Context applicationContext, Map&lt;String, Object&gt; customMaps, PrivacyInfo privacyInfo) {
        YourAdSDK.initCustomMap(customMaps);
        // Handle the privacy policy-related logic here
        MCDevPrivacyConfig devPrivacyConfig = privacyInfo.devPrivacyConfig;
    }

    @Override
    public void setLogDebug(boolean isLogDebug) {
        // Debug Log
    }

    @Override
    public void setPersonalizedAdState(int personalizedAdState) { }

    @Override
    public String getSdkVersion() { }

    @Override
    public void loadRewardedAd(Context context, MCLoadInfo loadInfo, final MCAdapterListener listener) {
        MCAdapterError adapterError = initParams(loadInfo);
        // Parse the loadInfo parameter. If parsing fails, trigger the failure callback
        if (adapterError != null) {
            listener.onAdLoadFail(adapterError);
            return;
        }
        // Create a rewarded ad object, initiate loading, and handle load-related callback events
        YourRewardedAd rewardedAd = new YourRewardedAd(context, loadInfo.getPlacementId());
        rewardedAd.setAdListener(new YourRewardedAdListener(){
            // Process load-related callback events at this location
            ...
            listener.onAdLoadSuccess(new YourAdInfo());
            ...
            listener.onAdLoadFail(&quot;load failed&quot;);
            ...
        });
        rewardedAd.load();
    }

    @Override
    public void loadInterstitialAd(Context context, MCLoadInfo loadInfo, final MCAdapterListener listener) {
        MCAdapterError adapterError = initParams(loadInfo);
        // Parse the loadInfo parameter. If parsing fails, trigger the failure callback
        if (adapterError != null) {
            listener.onAdLoadFail(adapterError);
            return;
        }
        // Create an interstitial ad object, initiate loading, and handle load-related callback events
        YourInterstitialAd interstitialAd = new YourInterstitialAd(context, loadInfo.getPlacementId());
        interstitialAd.setAdListener(new YourInterstitialAdListener(){
            // Process load-related callback events at this location
            ...
            listener.onAdLoadSuccess(new YourAdInfo());
            ...
            listener.onAdLoadFail(&quot;load failed&quot;);
            ...
        });
        interstitialAd.load();
    }

    @Override
    public void loadAdViewAd(Context context, MCLoadInfo loadInfo, final MCBannerSize bannerSize, MCAdapterListener listener) {
        MCAdapterError adapterError = initParams(loadInfo);
        // Parse the loadInfo parameter. If parsing fails, trigger the failure callback
        if (adapterError != null) {
            listener.onAdLoadFail(adapterError);
            return;
        }
        // Create a banner ad object, initiate loading, and handle load-related callback events
        YourBannerdAdView bannerdAd = new YourBannerdAdView(context, loadInfo.getPlacementId());
        bannerdAd.setAdListener(new YourBannerAdListener(){
            // Process load-related callback events at this location
            ...
            listener.onAdLoadSuccess(new YourAdInfo());
            ...
            listener.onAdLoadFail(&quot;load failed&quot;);
            ...
        });
        bannerdAd.load();
    }

    @Override
    public void loadAppOpenAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) {
        MCAdapterError adapterError = initParams(loadInfo);
        // Parse the loadInfo parameter. If parsing fails, trigger the failure callback
        if (adapterError != null) {
            listener.onAdLoadFail(adapterError);
            return;
        }
        // Create a splash ad object, initiate loading, and handle load-related callback events
        YourSplashdAd splashdAd = new YourSplashdAd(context, loadInfo.getPlacementId());
        splashdAd.setAdListener(new YourSplashAdListener(){
            // Process load-related callback events at this location
            ...
            listener.onAdLoadSuccess(new YourAdInfo());
            ...
            listener.onAdLoadFail(&quot;load failed&quot;);
            ...
        });
        splashdAd.load();
    }

    @Override
    public void loadNativeAd(Context context, MCLoadInfo loadInfo, MCAdapterListener listener) {
        MCAdapterError adapterError = initParams(loadInfo);
        // Parse the loadInfo parameter. If parsing fails, trigger the failure callback
        if (adapterError != null) {
            listener.onAdLoadFail(adapterError);
            return;
        }
        // Create a native ad object, initiate loading, and handle load-related callback events
        YourNativeAd nativeAd = new YourNativeAd(context, loadInfo.getPlacementId());
        nativeAd.setAdListener(new YourNativeAdListener(){
            // Process load-related callback events at this location
            ...
            // YourMCNativeAd extends MCNativeAd
            MCNativeAd.Builder builder = new MCNativeAd.Builder()
                    .isTemplateNativeAd(YourNativeAdView != null)
                    .setTitle(nativeAd.getTitle())
                    .setBody(nativeAd.getBody())
                    .setCallToAction(nativeAd.getCallToAction())
                    .setAdvertiser(nativeAd.getAdvertiser())
                    .setOptionsView(nativeAd.getOptionsView())
                    .setMediaContentAspectRatio(nativeAd.getMediaContentAspectRatio())
                    .setMediaView(nativeAd.getMediaView());
            listener.onAdLoadSuccess(new YourAdInfo(), new YourMCNativeAd(builder));
            ...
            listener.onAdLoadFail(&quot;load failed&quot;);
            ...
        });
        nativeAd.load();
    }

    @Override
    public View getBannerView() {
        return YourBannerdAdView;
    }

    @Override
    public boolean isAdReady() {
        // Check readiness status of various ad formats for display
    }

    @Override
    public void show(Activity activity, ViewGroup container, Map&lt;String, Object&gt; extra, MCAdapterListener listener) {
        // Manage display logic for rewarded ads, interstitial ads, and app open ads while handling associated callback events
        if (YourRewardedAd != null) {
            YourRewardedAd.show(activity);
            return;
        }
        if (YourInterstitialAd != null) {
            YourInterstitialAd.show(activity);
            return;
        }
        if (YourSplashdAd != null) {
            YourSplashdAd.show(activity);
            return;
        }
    }

    @Override
    public void destroy() { }

    @Override
    public void showMediationDebugger(Context context) { }
}
</code>
Previous
Advanced
Next
Customized Segment
Last modified: 2025-03-17Powered by