Manual Download for MAX Mediation Networks

Getting Started

To receive release updates, subscribe to the AppLovin-MAX-SDK-Android GitHub repository.

Download the Latest Android SDK

Add the SDK to the Project

Unzip the downloaded file, then drag and drop the aar file to the libs folder in your project. (If your project does not have a libs folder, you can create one inside the app folder.)

Gradle

Add the following to your build.gradle file:

  • repositories {
      google()
      mavenCentral()
      flatDir {
        dirs 'libs'
      }
      ⋮
    }
    dependencies {
      implementation 'com.applovin:applovin-sdk:x.y.z@aar'
      ⋮
    }
  • repositories {
      google()
      mavenCentral()
      flatDir {
        dirs("libs")
      }
      ⋮
    }
    dependencies {
      implementation("com.applovin:applovin-sdk:x.y.z@aar")
      ⋮
    }

Add the SDK Key

Add the following line into your AndroidManifest.xml. This needs to go inside the application tag:

<meta-data android:name="applovin.sdk.key"
           android:value="your-SDK-key"/>

You can find your SDK key in the Account > General > Keys section of the AppLovin dashboard.

Enable Ad Review

To enable the MAX Ad Review service, add the following to your build.gradle files:

Additions to Root-Level build.gradle File

  • buildscript {
      repositories {
        maven { url 'https://artifacts.applovin.com/android' }
      }
      dependencies {
        classpath "com.applovin.quality:AppLovinQualityServiceGradlePlugin:+"
      }
    }
  • buildscript {
      repositories {
        maven { url = uri("https://artifacts.applovin.com/android") }
      }
      dependencies {
        classpath ("com.applovin.quality:AppLovinQualityServiceGradlePlugin:+")
      }
    }

Additions to App-Level build.gradle File

You can find your Ad Review key in the Account > General > Keys section of the AppLovin dashboard.

Initialize the SDK

Initialize the SDK as soon as possible after your app starts, by calling the initializeSdk() method and passing in an Activity context. A good place to initialize is the onCreate() method of your launch Activity.

  • public class MainActivity extends Activity
    {
      protected void onCreate(Bundle savedInstanceState)
      {
        // Set the mediation provider value to "max" to ensure proper functionality.
        AppLovinSdk.getInstance( this ).setMediationProvider( "max" );
        AppLovinSdk.initializeSdk( this, new AppLovinSdk.SdkInitializationListener() {
          @Override
          public void onSdkInitialized(final AppLovinSdkConfiguration configuration)
          {
            // AppLovin SDK is initialized, start loading ads
          }
        } );
      }
    }
  • class MainActivity : Activity()
    {
      override fun onCreate(savedInstanceState: Bundle?)
      {
        // Set the mediation provider value to "max" to ensure proper functionality.
        AppLovinSdk.getInstance( this ).setMediationProvider( "max" )
        AppLovinSdk.getInstance( this ).initializeSdk({ configuration: AppLovinSdkConfiguration ->
          // AppLovin SDK is initialized, start loading ads
        })
      }
    }

Interstitial Ads

Loading an Interstitial Ad

To load an interstitial ad, instantiate a MaxInterstitialAd object with your ad unit and call loadAd(). Implement MaxAdListener so you can be notified when your ad is ready and of other ad-related events.

  • public class ExampleActivity extends Activity
            implements MaxAdListener
    {
      private MaxInterstitialAd interstitialAd;
      private int retryAttempt;
    
      void createInterstitialAd()
      {
        interstitialAd = new MaxInterstitialAd( "ad-unit-ID", this );
        interstitialAd.setListener( this );
    
        // Load the first ad
        interstitialAd.loadAd();
      }
    
      // MAX Ad Listener
      @Override
      public void onAdLoaded(final MaxAd maxAd)
      {
        // Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
    
        // Reset retry attempt
        retryAttempt = 0;
      }
    
      @Override
      public void onAdLoadFailed(final String adUnitId, final MaxError error)
      {
        // Interstitial ad failed to load
        // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
    
        retryAttempt++;
        long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
    
        new Handler().postDelayed( new Runnable()
        {
          @Override
          public void run()
          {
            interstitialAd.loadAd();
          }
        }, delayMillis );
      }
    
      @Override
      public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error)
      {
        // Interstitial ad failed to display. AppLovin recommends that you load the next ad
        interstitialAd.loadAd();
      }
    
      @Override
      public void onAdDisplayed(final MaxAd maxAd) {}
    
      @Override
      public void onAdClicked(final MaxAd maxAd) {}
    
      @Override
      public void onAdHidden(final MaxAd maxAd)
      {
        // Interstitial ad is hidden. Pre-load the next ad
        interstitialAd.loadAd();
      }
    }
  • class ExampleActivity : Activity(), MaxAdListener
    {
      private lateinit var interstitialAd: MaxInterstitialAd
      private var retryAttempt = 0.0
    
      fun createInterstitialAd()
      {
        interstitialAd = MaxInterstitialAd( "ad-unit-ID", this )
        interstitialAd.setListener( this )
    
        // Load the first ad
        interstitialAd.loadAd()
      }
    
      // MAX Ad Listener
      override fun onAdLoaded(maxAd: MaxAd)
      {
        // Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
    
        // Reset retry attempt
        retryAttempt = 0.0
      }
    
      override fun onAdLoadFailed(adUnitId: String?, error: MaxError?)
      {
        // Interstitial ad failed to load
        // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
    
        retryAttempt++
        val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
    
        Handler().postDelayed( { interstitialAd.loadAd() }, delayMillis )
      }
    
      override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?)
      {
        // Interstitial ad failed to display. AppLovin recommends that you load the next ad
        interstitialAd.loadAd()
      }
    
      override fun onAdDisplayed(maxAd: MaxAd) {}
    
      override fun onAdClicked(maxAd: MaxAd) {}
    
      override fun onAdHidden(maxAd: MaxAd)
      {
        // Interstitial ad is hidden. Pre-load the next ad
        interstitialAd.loadAd()
      }
    }

Showing an Interstitial Ad

To show an interstitial ad, call showAd() on the MaxInterstitialAd object created above.

  • if ( interstitialAd.isReady() )
    {
      interstitialAd.showAd();
    }
  • if ( interstitialAd.isReady )
    {
      interstitialAd.showAd()
    }

Rewarded Ads

Loading a Rewarded Ad

To load a rewarded ad, retrieve a MaxRewardedAd object with your rewarded ad unit and call loadAd() on it. Implement MaxRewardedAdListener so you can be notified when your ad is ready and of other ad-related events.

  • public class ExampleActivity extends Activity
            implements MaxRewardedAdListener
    {
      private MaxRewardedAd rewardedAd;
      private int           retryAttempt;
    
      void createRewardedAd()
      {
        rewardedAd = MaxRewardedAd.getInstance( "ad-unit-ID", this );
        rewardedAd.setListener( this );
    
        rewardedAd.loadAd();
      }
    
      // MAX Ad Listener
      @Override
      public void onAdLoaded(final MaxAd maxAd)
      {
        // Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
    
        // Reset retry attempt
        retryAttempt = 0;
      }
    
      @Override
      public void onAdLoadFailed(final String adUnitId, final int errorCode)
      {
        // Rewarded ad failed to load
        // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
    
        retryAttempt++;
        long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
    
        new Handler().postDelayed( new Runnable()
        {
          @Override
          public void run()
          {
            rewardedAd.loadAd();
          }
        }, delayMillis );
      }
    
      @Override
      public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error)
      {
        // Rewarded ad failed to display. AppLovin recommends that you load the next ad
        rewardedAd.loadAd();
      }
    
      @Override
      public void onAdDisplayed(final MaxAd maxAd) {}
    
      @Override
      public void onAdClicked(final MaxAd maxAd) {}
    
      @Override
      public void onAdHidden(final MaxAd maxAd)
      {
        // rewarded ad is hidden. Pre-load the next ad
        rewardedAd.loadAd();
      }
    
      @Override
      public void onRewardedVideoStarted(final MaxAd maxAd) {} // deprecated
    
      @Override
      public void onRewardedVideoCompleted(final MaxAd maxAd) {} // deprecated
    
      @Override
      public void onUserRewarded(final MaxAd maxAd, final MaxReward maxReward)
      {
        // Rewarded ad was displayed and user should receive the reward
      }
    }
  • class ExampleActivity : Activity(), MaxRewardedAdListener
    {
      private lateinit var rewardedAd: MaxRewardedAd
      private var retryAttempt = 0.0
    
      fun createRewardedAd()
      {
        rewardedAd = MaxRewardedAd.getInstance( "ad-unit-ID", this )
        rewardedAd.setListener( this )
    
        rewardedAd.loadAd()
      }
    
      // MAX Ad Listener
      override fun onAdLoaded(maxAd: MaxAd)
      {
        // Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
    
        // Reset retry attempt
        retryAttempt = 0.0
      }
    
      override fun onAdLoadFailed(adUnitId: String?, error: MaxError?)
      {
        // Rewarded ad failed to load
        // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
    
        retryAttempt++
        val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
    
        Handler().postDelayed( { rewardedAd.loadAd() }, delayMillis )
      }
    
      override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?)
      {
        // Rewarded ad failed to display. AppLovin recommends that you load the next ad
        rewardedAd.loadAd()
      }
    
      override fun onAdDisplayed(maxAd: MaxAd) {}
    
      override fun onAdClicked(maxAd: MaxAd) {}
    
      override fun onAdHidden(maxAd: MaxAd)
      {
        // rewarded ad is hidden. Pre-load the next ad
        rewardedAd.loadAd()
      }
    
      override fun onRewardedVideoStarted(maxAd: MaxAd) {} // deprecated
    
      override fun onRewardedVideoCompleted(maxAd: MaxAd) {} // deprecated
    
      override fun onUserRewarded(maxAd: MaxAd, maxReward: MaxReward)
      {
        // Rewarded ad was displayed and user should receive the reward
      }
    }

Showing a Rewarded Ad

To show a rewarded ad, call showAd() on the MaxRewardedAd object you created above.

  • if ( rewardedAd.isReady() )
    {
      rewardedAd.showAd();
    }
  • if ( rewardedAd.isReady() )
    {
      rewardedAd.showAd();
    }

Banners

Loading and Showing Banners Programmatically

To load a banner ad, create a MaxAdView object with your ad unit and call loadAd(). To show, add the MaxAdView object as a subview of your view hierarchy. Implement MaxAdViewAdListener so you can be notified when your ad is ready and of other ad-related events.

  • public class ExampleActivity extends Activity
            implements MaxAdViewAdListener
    {
      private MaxAdView adView;
    
      void createBannerAd()
      {
        adView = new MaxAdView( "ad-unit-ID", this );
        adView.setListener( this );
    
        // Stretch to the width of the screen for banners to be fully functional
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
    
        // Banner height on phones and tablets is 50 and 90, respectively
        int heightPx = getResources().getDimensionPixelSize( R.dimen.banner_height );
    
        adView.setLayoutParams( new FrameLayout.LayoutParams( width, heightPx ) );
    
        // Set background or background color for banners to be fully functional
        adView.setBackgroundColor( ... );
    
        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 int errorCode) {}
    
      @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) { /* use this for impression tracking */ }
    
      @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 */ }
    }
  • class ExampleActivity : Activity(), MaxAdViewAdListener
    {
      private var adView: MaxAdView? = null
    
      fun createBannerAd()
      {
        adView = MaxAdView("ad-unit-ID", this)
        adView?.setListener(this)
    
        // Stretch to the width of the screen for banners to be fully functional
        val width = ViewGroup.LayoutParams.MATCH_PARENT
    
        // Banner height on phones and tablets is 50 and 90, respectively
        val heightPx = resources.getDimensionPixelSize(R.dimen.banner_height)
    
        adView?.layoutParams = FrameLayout.LayoutParams(width, heightPx)
    
        // Set background or background color for banners to be fully functional
        adView?.setBackgroundColor(...)
    
        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) { /* use this for impression tracking */ }
    
      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 Banners in Layout Editor

Alternatively, you can add MAX banners to your view layout XML. Ensure that your banners are fully functional by setting a background or background color (android:background) and by stretching the width (android:layout_width) to the width of the screen:

<com.applovin.mediation.ads.MaxAdView
  xmlns:maxads="http://schemas.applovin.com/android/1.0"
  maxads:adUnitId="ad-unit-ID"
  android:background="@color/banner_background_color"
  android:layout_width="match_parent"
  android:layout_height="@dimen/banner_height" />

Declare the base banner height of 50dp in res/values/attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <dimen name="banner_height">50dp</dimen>
</resources>

Declare the tablet banner height of 90dp in res/values-sw600dp/attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <dimen name="banner_height">90dp</dimen>
</resources>

To hide a banner ad, call the following:

  • adView.setVisibility( View.GONE );
    adView.stopAutoRefresh();
  • adView.visibility = View.GONE
    adView.stopAutoRefresh()

To show a banner ad, call the following:

  • adView.setVisibility( View.VISIBLE );
    adView.startAutoRefresh();
  • adView.visibility = View.VISIBLE
    adView.startAutoRefresh()

MRECs

Loading and Showing MRECs Programmatically

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

  • public class ExampleActivity extends Activity
            implements MaxAdViewAdListener
    {
      private MaxAdView adView;
    
      void createMrecAd
      {
        adView = new MaxAdView( "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( ... );
    
        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 int errorCode) {}
    
      @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) { /* use this for impression tracking */ }
    
      @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 */ }
    }
  • class ExampleActivity : Activity(), MaxAdViewAdListener
    {
      private var adView: MaxAdView? = null
    
      fun createMrecAd
      {
        adView = MaxAdView("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(...)
    
        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) { /* use this for impression tracking */ }
    
      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. Ensure that your MRECs are fully functional by setting the ad format (android:adFormat) to "MREC" and by setting a background or background color (android:background):

<com.applovin.mediation.ads.MaxAdView
    xmlns:maxads="http://schemas.applovin.com/android/1.0"
    maxads:adUnitId="ad-unit-ID"
    maxads:adFormat="MREC"
    android:background="@color/mrec_background_color"
    android:layout_width="300dp"
    android:layout_height="250dp" />

To hide an MREC ad, call the following:

  • adView.setVisibility( View.GONE );
    adView.stopAutoRefresh();
  • adView.visibility = View.GONE
    adView.stopAutoRefresh()

To show an MREC ad, call the following:

  • adView.setVisibility( View.VISIBLE );
    adView.startAutoRefresh();
  • adView.visibility = View.VISIBLE
    adView.startAutoRefresh()

Preparing Mediated Networks

Select the ad networks to integrate. Then follow the specific instructions.

Minimum API Level Required

Nend requires Android API 19 (KitKat 4.4–4.4.4) or higher.

Migrating to AndroidX

Integrate AndroidX libraries into your project. Refer to the Migrate to AndroidX guide for more information on how to migrate your project.

Add Your Google AdMob / Google Ad Manager App ID

In your app’s AndroidManifest.xml, add a <meta-data> tag inside the <application> tag. In the example below, replace your-admob-app-id with your AdMob / Google Ad Manager App ID.

<?xml version="1.0" encoding="utf-8"?>
<manifest … >
  <application … >
    <meta-data
      android:name="com.google.android.gms.ads.APPLICATION_ID"
      android:value="your-admob-app-id"/>
    ⋮
  </application>
</manifest>

Google Mobile Ads SDK versions 20.5.0 and newer require that you set the compileSdkVersion of your app to 31 in build.gradle. Google Mobile Ads SDK version 20.4.0.1 is the most recent version that still supports setting compileSdkVersion to 30.

Use the latest Amazon Publisher Services adapter version to avoid reporting discrepancies.

Initialize the Amazon SDK

The Amazon Publisher Services SDK requires that you initialize it outside of MAX SDK:

// Amazon requires an 'Activity' instance
AdRegistration.getInstance( "AMAZON_APP_ID", this );
AdRegistration.setAdNetworkInfo( new DTBAdNetworkInfo( DTBAdNetwork.MAX ) );
AdRegistration.setMRAIDSupportedVersions( new String[] { "1.0", "2.0", "3.0" } );
AdRegistration.setMRAIDPolicy( MRAIDPolicy.CUSTOM );

Load a Banner Ad from Amazon’s SDK

Amazon leaders (tablet banners) are not supported. Only use Amazon banners when you create slot IDs in the Amazon dashboard.

To integrate Amazon ads into MAX, you must load the Amazon ad first, then pass the DTBAdResponse or AdError into the instance of MaxAdView by calling MaxAdView#setLocalExtraParameter() before you load the MAX ad.

For auto-refreshing banner ads you only need to load the ad once.

  • class ExampleActivity
            extends Activity
    {
      ⋮
    
      private void loadAd()
      {
        String amazonAdSlotId;
        MaxAdFormat adFormat;
    
        if ( AppLovinSdkUtils.isTablet( getApplicationContext() ) )
        {
          amazonAdSlotId = "Amazon-leader-slot-ID";
          adFormat = MaxAdFormat.LEADER;
        }
        else
        {
          amazonAdSlotId = "Amazon-banner-slot-ID";
          adFormat = MaxAdFormat.BANNER;
        }
    
        // Raw size will be 320x50 for BANNERs on phones, and 728x90 for LEADERs on tablets
        AppLovinSdkUtils.Size rawSize = adFormat.getSize();
        DTBAdSize size = new DTBAdSize( rawSize.getWidth(), rawSize.getHeight(), amazonAdSlotId );
    
        DTBAdRequest adLoader = new DTBAdRequest();
        adLoader.setSizes( size );
        adLoader.loadAd( new DTBAdCallback()
        {
          @Override
          public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
          {
            // 'adView' is your instance of MaxAdView
            adView.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
            adView.loadAd();
          }
          
          @Override
          public void onFailure(@NonNull final AdError adError)
          {
            // 'adView' is your instance of MaxAdView
            adView.setLocalExtraParameter( "amazon_ad_error", adError );
            adView.loadAd();
          }
        } );
      }
    }
  • class ExampleActivity : Activity()
    {
      private val adView: MaxAdView? = null
    
      private fun loadAd()
      {
        val amazonAdSlotId: String
        val adFormat: MaxAdFormat
    
        if (AppLovinSdkUtils.isTablet(applicationContext))
        {
          amazonAdSlotId = "Amazon-leader-slot-ID"
          adFormat = MaxAdFormat.LEADER
        }
        else
        {
          amazonAdSlotId = "Amazon-banner-slot-ID"
          adFormat = MaxAdFormat.BANNER
        }
    
        // Raw size will be 320x50 for BANNERs on phones, and 728x90 for LEADERs on tablets
        val rawSize = adFormat.size
        val size = DTBAdSize(rawSize.width, rawSize.height, amazonAdSlotId)
    
        val adLoader = DTBAdRequest()
        adLoader.setSizes(size)
        adLoader.loadAd(object : DTBAdCallback
        {
          override fun onSuccess(dtbAdResponse: DTBAdResponse)
          {
            // 'adView' is your instance of MaxAdView
            adView?.setLocalExtraParameter("amazon_ad_response", dtbAdResponse)
            adView?.loadAd()
          }
    
          override fun onFailure(adError: AdError)
          {
            // 'adView' is your instance of MaxAdView
            adView?.setLocalExtraParameter("amazon_ad_error", adError)
            adView?.loadAd()
          }
        })
      }
    }

Load an MREC Ad from Amazon’s SDK

To integrate Amazon MRECs into MAX, you must load the Amazon ad first, then pass the DTBAdResponse or AdError into the instance of MaxAdView by calling MaxAdView#setLocalExtraParameter() before you load the MAX ad.

  • class ExampleActivity
            extends Activity
    {
      ⋮
      private void loadAd()
      {
        String amazonAdSlotId;
    
        DTBAdRequest adLoader = new DTBAdRequest();
        adLoader.setSizes( new DTBAdSize( 300, 250, amazonAdSlotId ) );
        adLoader.loadAd( new DTBAdCallback()
        {
          @Override
          public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
          {
            // 'adView' is your instance of MaxAdView
            adView.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
            adView.loadAd();
          }
    
          @Override
          public void onFailure(@NonNull final AdError adError)
          {
            // 'adView' is your instance of MaxAdView
            adView.setLocalExtraParameter( "amazon_ad_error", adError );
            adView.loadAd();
          }
        } );
      }
    }
  • class ExampleActivity : Activity()
    {
      private val adView: MaxAdView? = null
    
      private fun loadAd()
      {
        val amazonAdSlotId: String
    
        val adLoader = DTBAdRequest()
        adLoader.setSizes(DTBAdSize(300, 250, amazonAdSlotId))
        adLoader.loadAd(object : DTBAdCallback
        {
          override fun onSuccess(dtbAdResponse: DTBAdResponse)
          {
            // 'adView' is your instance of MaxAdView
            adView!!.setLocalExtraParameter("amazon_ad_response", dtbAdResponse)
            adView.loadAd()
          }
    
          override fun onFailure(adError: AdError)
          {
            // 'adView' is your instance of MaxAdView
            adView!!.setLocalExtraParameter("amazon_ad_error", adError)
            adView.loadAd()
          }
        })
      }
    }

Load an Interstitial Ad from Amazon’s SDK

To integrate Amazon interstitial ads into MAX, you must load the Amazon ad first, then pass the DTBAdResponse or AdError into the instance of MaxInterstitialAd by calling MaxInterstitialAd#setLocalExtraParameter() before you load the MAX ad.

You must load and pass the Amazon DTBAdResponse or DTBAdErrorInfo into the MaxInterstitialAd instance only once per session.

  • class ExampleActivity
           extends Activity
    {
      private static MaxInterstitialAd interstitialAd; // static to ensure only one instance exists
      private static boolean           isFirstLoad = true;
    
      private void loadAd()
      {
        if ( isFirstLoad )
        {
          isFirstLoad = false;
    
          if ( interstitialAd == null )
          {
            interstitialAd = new MaxInterstitialAd( "MAX-inter-ad-unit-ID", this );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest();
          adLoader.setSizes( new DTBAdSize.DTBInterstitialAdSize( "Amazon-inter-slot-ID" ) );
          adLoader.loadAd( new DTBAdCallback()
          {
            @Override
            public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
              interstitialAd.loadAd();
            }
            
            @Override
            public void onFailure(@NonNull final AdError adError)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd.setLocalExtraParameter( "amazon_ad_error", adError );
              interstitialAd.loadAd();
            }
          } );
        }
        else
        {
          interstitialAd.loadAd();
        }
      }
    }
  • class ExampleActivity : Activity()
    {
      private var interstitialAd: MaxInterstitialAd? = null // static to ensure only one instance exists
      private var isFirstLoad = true
    
      private fun loadAd()
      {
        if (isFirstLoad)
        {
          isFirstLoad = false
    
          if (interstitialAd == null)
          {
            interstitialAd = MaxInterstitialAd("MAX-inter-ad-unit-ID", this)
          }
    
          val adLoader = DTBAdRequest()
          adLoader.setSizes(DTBAdSize.DTBInterstitialAdSize("Amazon-inter-slot-ID"))
          adLoader.loadAd(object : DTBAdCallback
          {
            override fun onSuccess(dtbAdResponse: DTBAdResponse)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd!!.setLocalExtraParameter("amazon_ad_response", dtbAdResponse)
              interstitialAd!!.loadAd()
            }
    
            override fun onFailure(adError: AdError)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd!!.setLocalExtraParameter("amazon_ad_error", adError)
              interstitialAd!!.loadAd()
            }
          })
        }
        else
        {
          interstitialAd!!.loadAd()
        }
      }
    }

Load a Video Interstitial Ad from Amazon’s SDK

To integrate Amazon video interstitial ads into MAX, you must load the Amazon ad first, then pass the DTBAdResponse or AdError into the instance of MaxInterstitialAd by calling MaxInterstitialAd#setLocalExtraParameter() before you load the MAX ad.

You must load and pass the Amazon DTBAdResponse or DTBAdErrorInfo into the MaxInterstitialAd instance only once per session.

  • class ExampleActivity
           extends Activity
    {
      private static MaxInterstitialAd interstitialAd; // static to ensure only one instance exists
      private static boolean           isFirstLoad = true;
    
      private void loadAd()
      {
        if ( isFirstLoad )
        {
          isFirstLoad = false;
    
          if ( interstitialAd == null )
          {
            interstitialAd = new MaxInterstitialAd( "MAX-inter-ad-unit-ID", this );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest();
    
          // Switch video player width and height values(320, 480) depending on device orientation
          adLoader.setSizes( new DTBAdSize.DTBVideo(320, 480, "Amazon-video-inter-slot-ID") );
          adLoader.loadAd( new DTBAdCallback()
          {
            @Override
            public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
              interstitialAd.loadAd();
            }
    
            @Override
            public void onFailure(@NonNull final AdError adError)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd.setLocalExtraParameter( "amazon_ad_error", adError );
              interstitialAd.loadAd();
            }
          } );
        }
        else
        {
          interstitialAd.loadAd();
        }
      }
    }
  • class ExampleActivity : Activity()
    {
      private var interstitialAd: MaxInterstitialAd? = null // static to ensure only one instance exists
      private var isFirstLoad = true
    
      private fun loadAd()
      {
        if (isFirstLoad)
        {
          isFirstLoad = false
    
          if (interstitialAd == null)
          {
            interstitialAd = MaxInterstitialAd("MAX-inter-ad-unit-iD", this)
          }
    
          val adLoader = DTBAdRequest()
    
          // Switch video player width and height values(320, 480) depending on device orientation
          adLoader.setSizes(DTBAdSize.DTBVideo(320, 480, "Amazon-video-inter-slot-ID"))
          adLoader.loadAd(object : DTBAdCallback
          {
            override fun onSuccess(dtbAdResponse: DTBAdResponse)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd!!.setLocalExtraParameter("amazon_ad_response", dtbAdResponse)
              interstitialAd!!.loadAd()
            }
    
            override fun onFailure(adError: AdError)
            {
              // 'interstitialAd' is your instance of MaxInterstitialAd
              interstitialAd!!.setLocalExtraParameter("amazon_ad_error", adError)
              interstitialAd!!.loadAd()
            }
          })
        }
        else
        {
          interstitialAd!!.loadAd()
        }
      }
    }

Load a Rewarded Video Ad from Amazon’s SDK

To integrate Amazon rewarded videos into MAX, first load the Amazon ad, then pass the DTBAdResponse or AdError into the instance of MaxRewardedAd by calling MaxRewardedAd#setLocalExtraParameter() before you load the MAX ad.

You must load and pass the Amazon DTBAdResponse or AdError into the MaxRewardedAd instance only once per session.

  • class ExampleActivity
            extends Activity
    {
      private static MaxRewardedAd rewardedAd; // static to ensure only one instance exists
      private static boolean       isFirstLoad = true;
    
      private void loadAd()
      {
        if ( isFirstLoad )
        {
          isFirstLoad = false;
    
          if ( rewardedAd == null )
          {
            rewardedAd = MaxRewardedAd.getInstance( "MAX-rewarded-ad-unit-ID", this );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest();
    
          // Switch video player width and height values(320, 480) depending on device orientation
          adLoader.setSizes( new DTBAdSize.DTBVideo( 320, 480, "Amazon-video-rewarded-slot-ID" ) );
          adLoader.loadAd( new DTBAdCallback()
          {
            @Override
            public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
            {
              // 'rewardedAd' is your instance of MaxRewardedAd
              rewardedAd.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
              rewardedAd.loadAd();
            }
    
            @Override
            public void onFailure(@NonNull final AdError adError)
            {
              // 'rewardedAd' is your instance of MaxRewardedAd
              rewardedAd.setLocalExtraParameter( "amazon_ad_error", adError );
              rewardedAd.loadAd();
            }
          } );
        }
        else
        {
          rewardedAd.loadAd();
        }
      }
    }
  • class ExampleActivity
            extends Activity
    {
      private static MaxRewardedAd rewardedAd; // static to ensure only one instance exists
      private static boolean       isFirstLoad = true;
    
      private void loadAd()
      {
        if ( isFirstLoad )
        {
          isFirstLoad = false;
    
          if ( rewardedAd == null )
          {
            rewardedAd = MaxRewardedAd.getInstance( "MAX-rewarded-ad-unit-ID", this );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest();
    
          // Switch video player width and height values(320, 480) depending on device orientation
          adLoader.setSizes( new DTBAdSize.DTBVideo( 320, 480, "Amazon-video-rewarded-slot-ID" ) );
          adLoader.loadAd( new DTBAdCallback()
          {
            @Override
            public void onSuccess(@NonNull final DTBAdResponse dtbAdResponse)
            {
              // 'rewardedAd' is your instance of MaxRewardedAd
              rewardedAd.setLocalExtraParameter( "amazon_ad_response", dtbAdResponse );
              rewardedAd.loadAd();
            }
    
            @Override
            public void onFailure(@NonNull final AdError adError)
            {
              // 'rewardedAd' is your instance of MaxRewardedAd
              rewardedAd.setLocalExtraParameter( "amazon_ad_error", adError );
              rewardedAd.loadAd();
            }
          } );
        }
        else
        {
          rewardedAd.loadAd();
        }
      }
    }

Testing Amazon Publisher Services

AppLovin recommends that you enable test mode for Amazon’s SDK to receive test ads. You can do this with the following calls:

AdRegistration.enableTesting( true );
AdRegistration.enableLogging( true );

To filter your waterfalls to contain only Amazon ads, navigate to Select Live Network in the Mediation Debugger and select the Amazon network.

Enable Google Ad Manager

In your app’s AndroidManifest.xml, add a <meta-data> tag inside the <application> tag, as in the example below:

<?xml version="1.0" encoding="utf-8"?>
<manifest … >
  <application … >
    <meta-data
        android:name="com.google.android.gms.ads.AD_MANAGER_APP"
        android:value="true"/>
    ⋮
  </application>
</manifest>

Meta Audience Network Data Processing Options

If you do not want to enable Limited Data Use (LDU) mode, pass SetDataProcessingOptions() an empty string array:

  • import com.facebook.ads.AdSettings;
    ⋮
    AdSettings.setDataProcessingOptions( new String[] {} );
    ⋮
    // Initialize MAX SDK
  • import com.facebook.ads.AdSettings
    ⋮
    AdSettings.setDataProcessingOptions( arrayOf<String>() )
    ⋮
    // Initialize MAX SDK

To enable LDU for users and specify user geography, call SetDataProcessingOptions() in a form like this:

  • import com.facebook.ads.AdSettings;
    ⋮
    AdSettings.setDataProcessingOptions( new String[] {"LDU"}, 1, 1000 );
    ⋮
    // Initialize MAX SDK
  • import com.facebook.ads.AdSettings
    ⋮
    AdSettings.setDataProcessingOptions( arrayOf("LDU"), 1, 1000 )
    ⋮
    // Initialize MAX SDK

Meta Audience Network Data Processing Options for Users in California

For information about how to implement Meta Audience Network’s “Limited Data Use” flag in California, visit the Meta for Developers documentation.

Android Manifest Merging Errors

Several network SDKs use the <queries> element in their bundled Android Manifest files. If you are on an incompatible version of the Android Gradle plugin, this will cause one of the following build errors:

  • com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
    error: unexpected element <queries> found in <manifest>.
  • Missing 'package' key attribute on element package at [:com.my.target.mytarget-sdk-5.11.3:]
    AndroidManifest Validation failed

To fix this error, upgrade to one of the following versions of the Android Gradle plugin that supports the <queries> element:

Upgrade the Android Gradle Plugin, not the Gradle Build Tools.

Current Android Gradle Plugin Version Version that Supports <queries> Element
4.1.* All
4.0.* 4.0.1+
3.6.* 3.6.4+
3.5.* 3.5.4+
3.4.* 3.4.3+
3.3.* 3.3.3+

Refer to the Mediation Matrix for the SDK version supported for each network.

If you are interested in receiving callbacks to your currency server, please see the MAX S2S Rewarded Callback API guide and update the S2S Rewarded Callback URL in your MAX ad unit page.