Skip to content

Android SDK - MREC ads

MREC (medium rectangle) ads are 300×250 ads placed inside your app's content, such as in a list or feed, or on screens where the user pauses, like a level-complete screen. Like banners, they stay visible while users interact with your app.

Before you start, install and initialize the SDK.

1. Get the MREC ad object

Get the ad object for your ad unit ID. The SDK caches one instance per ad unit, so calling getMrecAd again with the same ID returns the same object. Call after initializing MDN11 SDK.

private val mrec by lazy { A11.getMrecAd("adUnitId") }

2. Set the listener

Set the listener before calling load(), so you don't miss any events. When onMrecAdLoaded fires, call show() to display the MREC.

mrec.listener = object : MrecAdListener {
    override fun onMrecAdLoaded(adInfo: AdInfo) {
        mrec.show(activity)
    }
    override fun onMrecAdLoadFailed(error: LoadError) {
        Log.e("Ads", "MREC load failed: $error")
    }
    override fun onMrecAdShown(adInfo: AdInfo) {}
    override fun onMrecAdShowFailed(adInfo: AdInfo?, error: ShowError) {
        Log.e("Ads", "MREC show failed: $error")
    }
    override fun onMrecAdClicked(adInfo: AdInfo) {}
    override fun onMrecAdRevenue(adInfo: AdInfo) {}
}

3. Add the view and load the ad

Add view to your layout before calling load(). The view stays the same when the ad inside it changes, so add it only once.

myMrecContainer.addView(mrec.view)
mrec.load(activity)

Full example

private val mrec by lazy { A11.getMrecAd("adUnitId") }

fun setupMrec() {
    mrec.listener = object : MrecAdListener {
        override fun onMrecAdLoaded(adInfo: AdInfo) {
            mrec.show(activity)
        }
        override fun onMrecAdLoadFailed(error: LoadError) {
            Log.e("Ads", "MREC load failed: $error")
        }
        override fun onMrecAdShown(adInfo: AdInfo) {}
        override fun onMrecAdShowFailed(adInfo: AdInfo?, error: ShowError) {
            Log.e("Ads", "MREC show failed: $error")
        }
        override fun onMrecAdClicked(adInfo: AdInfo) {}
        override fun onMrecAdRevenue(adInfo: AdInfo) {}
    }

    // Place the stable view in your layout, then load
    myMrecContainer.addView(mrec.view)
    mrec.load(activity)
}

MREC refresh

Caution

MDN11 currently does not support auto-refresh, so you need to load and show new MRECs manually. Refresh only while the MREC is on screen. Stop refreshing when the app goes to the background or the user moves to a screen without the MREC, so you don't request ads nobody sees. If your current mediation platform (for example MAX, LevelPlay or AdMob) has auto-refresh turned on for MRECs, you can't use MDN11 for MRECs yet. Call that platform's SDK directly instead.