Skip to content

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

Initialize the SDK by calling the initializeSdk() method, passing that method a context. Do this as soon as possible after your app starts, for example in 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
}
} );
}
}

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();
}
}

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»", 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 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();
}

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»", 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 */ }
}

Loading and Showing Banners or MRECs in Layout Editor

Alternatively, you can 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). In the case of banners, stretch the width (android:layout_width) to the width of the screen. In the case of 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 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 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.

Manual Download for MAX Mediation Networks