AppLovinMax_Android_MRECs - imobile/app-mediation GitHub Wiki

MRECs

Loading and Showing MRECs Programmatically

To load an MREC ad, create a MaxAdView object corresponding to your ad unit and call its loadAd() method. To show the ad, add the MaxAdView object as a subview of your view hierarchy. Implement MaxAdViewAdListener so that you are notified when your ad is ready and of other ad-related events.

// Java

public class ExampleActivity extends Activity
        implements MaxAdViewAdListener
{
    private MaxAdView adView;

    void createMrecAd
    {
        adView = new MaxAdView( "YOUR_AD_UNIT_ID", MaxAdFormat.MREC, this );
        adView.setListener( this );
    
        // MREC width and height are 300 and 250 respectively, on phones and tablets
        int widthPx = AppLovinSdkUtils.dpToPx( this, 300 );
        int heightPx = AppLovinSdkUtils.dpToPx( this, 250 );
    
        adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
    
        // Set background or background color for MRECs to be fully functional
        adView.setBackgroundColor( R.color.background_color );
    
        ViewGroup rootView = findViewById( android.R.id.content );
        rootView.addView( adView );
    
        // Load the ad
        adView.loadAd();
    }

    // MAX Ad Listener
    @Override
    public void onAdLoaded(final MaxAd maxAd) {}

    @Override
    public void onAdLoadFailed(final String adUnitId, final MaxError error) {}

    @Override
    public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) {}

    @Override
    public void onAdClicked(final MaxAd maxAd) {}

    @Override
    public void onAdExpanded(final MaxAd maxAd) {}

    @Override
    public void onAdCollapsed(final MaxAd maxAd) {}
    
    @Override
    public void onAdDisplayed(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }

    @Override
    public void onAdHidden(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}
// Kotlin

class ExampleActivity : Activity(), MaxAdViewAdListener
{
    private var adView: MaxAdView? = null

    fun createMrecAd
    {
        adView = MaxAdView("YOUR_AD_UNIT_ID", MaxAdFormat.MREC, this)
        adView!!.setListener(this)
    
        // MREC width and height are 300 and 250 respectively, on phones and tablets
        val widthPx = AppLovinSdkUtils.dpToPx(this, 300)
        val heightPx = AppLovinSdkUtils.dpToPx(this, 250)
    
        adView!!.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
    
        // Set background or background color for MRECs to be fully functional
        adView!!.setBackgroundColor(R.color.background_color)
    
        val rootView = findViewById<ViewGroup>(android.R.id.content)
        rootView.addView(adView)
    
        // Load the ad
        adView!!.loadAd()
    }

    // MAX Ad Listener
    override fun onAdLoaded(maxAd: MaxAd) {}

    override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}

    override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}

    override fun onAdClicked(maxAd: MaxAd) {}

    override fun onAdExpanded(maxAd: MaxAd) {}

    override fun onAdCollapsed(maxAd: MaxAd) {}

    override fun onAdDisplayed(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
    
    override fun onAdHidden(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}

Loading and Showing MRECs in Layout Editor

Alternatively, you can add MAX MRECs to your view layout XML:

<com.applovin.mediation.ads.MaxAdView
    xmlns:maxads="http://schemas.applovin.com/android/1.0"
    maxads:adUnitId="YOUR_AD_UNIT_ID"
    maxads:adFormat="MREC"                            <!-- Set the ad format for MRECs to be fully functional -->
    android:background="@color/mrec_background_color" <!-- Set background or background color for MRECs to be fully functional -->
    android:layout_width="300"
    android:layout_height="250"
</com.applovin.mediation.ads.MaxAdView>

To hide an MREC ad, make the following calls:

// Java

adView.setVisibility( View.GONE );
adView.stopAutoRefresh();
// Kotlin

adView.visibility = View.GONE
adView.stopAutoRefresh()

To show an MREC ad, make the following calls:

// Java

adView.setVisibility( View.VISIBLE );
adView.startAutoRefresh();
// Kotlin

adView.visibility = View.VISIBLE
adView.startAutoRefresh()
⚠️ **GitHub.com Fallback** ⚠️