Manual download for MAX mediation networks

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'
  ⋮
}

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:+"
  }
}

Additions to app-level build.gradle file

apply plugin: 'applovin-quality-service'
applovin {
    apiKey "«your-ad-review-key»"
}

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

Initialize the SDK

Create the SDK initialization configuration

Before you initialize the SDK, create an initialization configuration object for the SDK. This object allows you to configure the properties that the SDK will initialize with. These initialization properties are immutable, except AppLovinSdkSettings which contains mutable properties that can change during the lifetime of the app.

// Create the initialization configuration
AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»" )
                 .setMediationProvider( AppLovinMediationProvider.MAX )
// Perform any additional configuration/setting changes
                 .build();

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

Initialize the SDK

Initialize the AppLovin SDK with the initialization configuration object as early as possible (for example, in the onCreate() of the launch activity or Application class). This maximizes how much time the SDK has to cache mediated networks’ ads, which results in a better user experience.

public class MainActivity extends Activity
{
  protected void onCreate(Bundle savedInstanceState)
  {
    // Create the initialization configuration
    AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»" )
                     .setMediationProvider( AppLovinMediationProvider.MAX )
                     .build();

    // Initialize the SDK with the configuration
    AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
    {
      @Override
      public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
      {
        // Start loading ads
      }
    } );
  }
}

Example

Below is a sample integration.

// Create the initialization configuration
AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»" )
    .setMediationProvider( AppLovinMediationProvider.MAX )
    .setSegmentCollection( MaxSegmentCollection.builder()
                             .addSegment( new MaxSegment( 849, Arrays.asList( 1, 3 ) ) )
                             .build() )
    .build();

// Configure the SDK settings if needed before or after SDK initialization.
val settings = AppLovinSdk.getInstance( this ).getSettings();
settings.setUserIdentifier( "«user-ID»" );
settings.setExtraParameter( "uid2_token", "«token-value»" );
settings.getTermsAndPrivacyPolicyFlowSettings().setEnabled( true );
settings.getTermsAndPrivacyPolicyFlowSettings().setPrivacyPolicyUri( Uri.parse( "«https://your-company-name.com/privacy-policy»" ) );
settings.getTermsAndPrivacyPolicyFlowSettings().setTermsOfServiceUri( Uri.parse( "«https://your-company-name.com/terms-of-service»" ) );

// Initialize the SDK with the configuration
AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
{
  @Override
  public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
  {
    // 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»" );
    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();
  }
}

Showing an interstitial ad

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

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»" );
    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 onUserRewarded(final MaxAd maxAd, final 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();
}

To learn how to receive callbacks to your currency server, see the MAX S2S rewarded callback API guide and update the S2S Rewarded Callback URL in your Edit Ad Unit page.

Banners & MRECs

Loading and showing banners & MRECs programmatically

To load a banner ad or MREC, 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»" );
    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 */ }
}

Loading and showing banners or MRECs in layout editor

You can also add MAX banners or MRECs to your view layout XML. Ensure that your ads are fully functional by setting a background or background color (android:background). For banners, stretch the width (android:layout_width) to the width of the screen. For MRECs, set the android:adFormat accordingly:

<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 50 dp 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 90 dp 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 or MREC ad, call the following:

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

To show a banner or MREC ad, call the following:

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

Preparing mediated networks

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

  • Amazon
  • Google Ad Manager
  • Google Bidding and Google AdMob
  • Liftoff Monetize
  • Meta Audience Network
  • Mintegral
  • 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.

    Developers and publishers who use Google AdSense, AdManager, or AdMob must use a consent management platform (CMP) that Google certifies. The CMP must integrate with IAB’s Transparency and Consent Framework when you serve ads to users in the European Economic Area (EEA) or the UK. See Privacy: “TCF v2 consent” for more information.

    Add your Google bidding and Google AdMob / Google Ad Manager app ID

    In your app’s AndroidManifest.xml, add a <meta-data> tag inside the <application> tag. The example below shows you the correct attributes of this tag. Replace «your-admob-app-id» with your Google bidding and Google 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>

    Gradle errors

    Google AdMob requires Android Gradle plugin version 4.2.0 or higher and Gradle version 6.7.1 or higher. If you see the following error, update your Android Gradle plugin and Gradle versions:

    AAPT: error: unexpected element <property> found in <manifest><application>.
    

    compileSdkVersion

    Google Mobile Ads SDK versions 23.1.0 and newer require a compileSdkVersion of at least 34.

    Set the compileSdkVersion to 34 or higher in your app’s build.gradle.

    Refer to the Google Mobile Ads SDK Release Notes for the latest compileSdkVersion requirements.

    Initialize the Amazon SDK

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

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

    Load a banner or MREC ad from Amazon’s SDK

    To integrate Amazon ads into MAX, you must load the Amazon ad first. Before you load the MAX ad, pass the DTBAdResponse or AdError into the instance of MaxAdView. You can do this by calling MaxAdView#setLocalExtraParameter().

    For auto-refreshing banner ads, you only need to load the ad one time.

    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( getApplicationContext(), new DTBAdNetworkInfo( ApsAdNetwork.MAX ) );
        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();
          }
        } );
      }
    }

    Load an interstitial ad from Amazon’s SDK

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

    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»" );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest( getApplicationContext(), new DTBAdNetworkInfo( ApsAdNetwork.MAX ) );
          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();
        }
      }
    }

    Load a video interstitial ad from Amazon’s SDK

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

    You must load and pass the 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»" );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest( getApplicationContext(), new DTBAdNetworkInfo( ApsAdNetwork.MAX ) );
    
          // 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();
        }
      }
    }

    Load a rewarded video ad from Amazon’s SDK

    To integrate Amazon rewarded videos into MAX, first load the Amazon ad. Before you load the MAX ad, pass the DTBAdResponse or AdError into the instance of MaxRewardedAd. You can do this by calling MaxRewardedAd#setLocalExtraParameter().

    You must load and pass the 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»" );
          }
    
          DTBAdRequest adLoader = new DTBAdRequest( getApplicationContext(), new DTBAdNetworkInfo( ApsAdNetwork.MAX ) );
    
          // 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. This allows you to receive test ads. Enable test mode by making the following calls:

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

    You can filter your waterfalls such that they contain only Amazon ads. To do this, navigate to Select Live Network in the Mediation Debugger and select the Amazon network.

    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

    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"}, «country», «state» );
    ⋮
    // Initialize MAX SDK

    Using Google UMP

    If you use Google UMP as your CMP, you can determine whether the user has consented to Meta or not. To do so, use code like the following:

    Boolean hasMetaConsent = AppLovinPrivacySettings.getAdditionalConsentStatus( 89 );
    if ( hasMetaConsent != null )
    {
      // Set Meta Data Processing Options accordingly.
    }
    else
    {
      // AC String is not available on disk. Please check for consent status after the user completes the CMP flow.
    }

    Meta Audience Network data processing options for users in California

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

    Android manifest merging errors

    Some network SDKs include the <queries> element in their bundled Android Manifest files. If you use an incompatible version of the Android Gradle plugin, this causes one of the following build errors:

    com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
    error: unexpected element <queries> found in <manifest>.
    

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

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

    Current Android Gradle plugin versionVersion 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+

    Manual download for MAX mediation networks

    Loading…

    Was this article helpful?
    Was this article helpful?
    search