AppLovin MAX mediation
This article shows you how to deliver Teads ads in your application using the AppLovin Mediation adapter.
The official Teads SDK sample application includes working AppLovin MAX integrations. Use it for implementation examples and as a reference while you set up this adapter.
Prerequisites
- Import the Teads inApp SDK in your project.
- AppLovin SDK: 11+
Installation
Before installing the Teads AppLovin adapter, you will need to integrate AppLovin SDK into your application.
Gradle
project/build.gradle
allprojects {
repositories {
...
maven { url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod" }
}
}
app/build.gradle
dependencies {
...
implementation "com.applovin:applovin-sdk:11.5.1" // or higher
// Teads inApp SDK
implementation("tv.teads.sdk.android:sdk:6.2.3@aar") {
transitive = true
}
// Teads AppLovin Adapter
implementation 'tv.teads.sdk.android:applovinadapter:6.2.3'
}
Defining a Custom network
In order to display a Teads ad using AppLovin mediation, you need to create a new Teads custom network and a new adunit using Teads custom network.
Teads Custom Network
Follow the custom network documentation (Step. 1) on the AppLovin dashboard using the below values.
| Name | Value |
|---|---|
| Android Class Name | com.applovin.mediation.adapters.TeadsContextAdapter |
Teads Ad Unit
Follow the custom network documentation (Step. 2) on the AppLovin dashboard using the below values.
| Name | Value |
|---|---|
| Placement ID (PID) | Teads placement ID — use 84242 (Media) or 124859 (Native) for testing. Production PIDs come from your account manager. |
Production PIDs come from your account manager. See the troubleshooting guide for test PIDs and creative formats.
Formats
Pick the ad format you are integrating. Each format has its own setup.
- Media
- Native Ad
Load an ad
You will need to initialize the AppLovinSdk, then pass your Ad Unit ID that you created before,
pass the teads settings using the teadsSettings key
- Kotlin
- Java
AppLovinSdk.getInstance(this).mediationProvider = "max"
AppLovinSdk.getInstance(this).initializeSdk {} // you will need to wait this to finish before loading an ad
val adView = MaxAdView("YOUR_AD_UNIT_ID", MaxAdFormat.MREC,this)
val settingsEncoded = TeadsMediationSettings.Builder()
.build()
.toJsonEncoded()
adView.setLocalExtraParameter("teadsSettings", settingsEncoded)
adView.loadAd()
AppLovinSdk.getInstance(this).setMediationProvider("max");
AppLovinSdk.getInstance(this).initializeSdk(configuration -> {}); // you will need to wait this to finish before loading an ad
MaxAdView adView = new MaxAdView("YOUR_AD_UNIT_ID", MaxAdFormat.MREC, this);
String settingsEncoded = new TeadsMediationSettings.Builder()
.build()
.toJsonEncoded();
adView.setLocalExtraParameter("teadsSettings", settingsEncoded);
adView.loadAd();
Ad Resizing
The code below must be implemented to enable the resizing of the mediated ad slot making possible the rendering of square and vertical creatives.
Initialize the TeadsHelper first.
- Kotlin
- Java
TeadsHelper.initialize()
TeadsHelper.initialize();
You can instantiate a new listener as below, the listener needs to be a class member field or strong referenced somewhere, we keep internally a weak reference to it, so it goes garbage collected when you don't need it anymore:
- Kotlin
- Java
listener = object : TeadsAdapterListener {
override fun onRatioUpdated(adRatio: AdRatio) {
val params: ViewGroup.LayoutParams = adView.layoutParams
// Here the width is MATCH_PARENT
params.height = adRatio.calculateHeight(adView.measuredWidth)
adView.layoutParams = params
}
override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) {
}
}
listener = new TeadsAdapterListener() {
@Override
public void onRatioUpdated(AdRatio adRatio) {
ViewGroup.LayoutParams params = adView.getLayoutParams();
// Here the width is MATCH_PARENT
params.height = adRatio.calculateHeight(adView.getMeasuredWidth());
adView.setLayoutParams(params);
}
@Override
public void adOpportunityTrackerView(AdOpportunityTrackerView trackerView) {
}
};
Use the helper to attach a listener, it will return you a UNIQUE key to reference the current listener attached.
- Kotlin
- Java
val key = TeadsHelper.attachListener(listener)
int key = TeadsHelper.attachListener(listener);
Before loading the ad you can define if you want to disable ad auto-refreshing. This AppLovin mediation feature works like an ad caching system: it automatically requests new ads and queues them to display sequentially on the same ad slot.
If you do not disable it, use it carefully: ads that load often but are not displayed will reduce your ad fill rate.
To adjust the ad refresh interval, check the official documentation.
To disable it, add the following lines.
- Kotlin
- Java
adView.setExtraParameter( "allow_pause_auto_refresh_immediately", "true" )
adView.stopAutoRefresh()
adView.setExtraParameter("allow_pause_auto_refresh_immediately", "true");
adView.stopAutoRefresh();
Finally, add it to your current ad settings for the specific ad request.
- Kotlin
- Java
val settingsEncoded = TeadsMediationSettings.Builder()
.enableDebug()
.setMediationListenerKey(key)
.build().toJsonEncoded()
adView.setLocalExtraParameter("teadsSettings", settingsEncoded)
String settingsEncoded = new TeadsMediationSettings.Builder()
.enableDebug()
.setMediationListenerKey(key)
.build().toJsonEncoded();
adView.setLocalExtraParameter("teadsSettings", settingsEncoded);
This native implementation is specifically designed to fit feed views. You can customize the ad view to look like the other cells around, to offer a more immersive experience.
Display an ad
Create your custom layout
Create your new layout for an ad item with your favorite ViewGroup container (eg. RelativeLayout, ConstraintLayout ...)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/ad_headline"
...
/>
<FrameLayout
android:id="@+id/media_view_container"
...
/>
// THIS CONTAINER IS MANDATORY, IT WILL BE USED AS AD_CHOICES
<FrameLayout
android:id="@+id/ad_options_view"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
...
/>
...
</RelativeLayout>
Native Ad Elements
titleView(Guaranteed in every request)mediaView(Guaranteed in every request)adChoicesView(Mandatory)bodyViewcallToActionViewiconViewadvertiserView
Request an ad
Create the View binder
Take your layout id and pass it to the builder constructor MaxNativeAdViewBinder.Builder,
fill every field you need for your integration
- Kotlin
- Java
private fun createNativeAdView(): MaxNativeAdView {
val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.layout_applovin_native)
.setTitleTextViewId(R.id.title_text_view) // MANDATORY
.setBodyTextViewId(R.id.body_text_view)
.setAdvertiserTextViewId(R.id.advertiser_textView)
.setIconImageViewId(R.id.icon_image_view)
.setMediaContentViewGroupId(R.id.media_view_container) // MANDATORY
.setOptionsContentViewGroupId(R.id.ad_options_view) // MANDATORY (AdChoices)
.setCallToActionButtonId(R.id.cta_button)
.build()
return MaxNativeAdView(binder, this)
}
private MaxNativeAdView createNativeAdView() {
MaxNativeAdViewBinder binder = new MaxNativeAdViewBinder.Builder(R.layout.layout_applovin_native)
.setTitleTextViewId(R.id.title_text_view) // MANDATORY
.setBodyTextViewId(R.id.body_text_view)
.setAdvertiserTextViewId(R.id.advertiser_textView)
.setIconImageViewId(R.id.icon_image_view)
.setMediaContentViewGroupId(R.id.media_view_container) // MANDATORY
.setOptionsContentViewGroupId(R.id.ad_options_view) // MANDATORY (AdChoices)
.setCallToActionButtonId(R.id.cta_button)
.build();
return new MaxNativeAdView(binder, this);
}
Create the AdLoader
- Kotlin
- Java
AppLovinSdk.getInstance(this).mediationProvider = "max"
AppLovinSdk.getInstance(this).initializeSdk {} // you will need to wait this to finish before loading an ad
val nativeAdLoader = MaxNativeAdLoader("YOUR_AD_UNIT_ID", this)
nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() {
override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView, ad: MaxAd) {
// Destroy previous ad if exists
if (nativeAd != null) nativeAdLoader.destroy(nativeAd)
// Store the new ad to allow destroying it later
nativeAd = ad
// Add ad view to container
containerAdView.removeAllViews()
containerAdView.addView(nativeAdView)
}
override fun onNativeAdLoadFailed(adUnitId: String, error: MaxError) {}
override fun onNativeAdClicked(ad: MaxAd) {}
})
AppLovinSdk.getInstance(this).setMediationProvider("max");
AppLovinSdk.getInstance(this).initializeSdk(configuration -> {}); // you will need to wait this to finish before loading an ad
MaxNativeAdLoader nativeAdLoader = new MaxNativeAdLoader("YOUR_AD_UNIT_ID", this);
nativeAdLoader.setNativeAdListener(new MaxNativeAdListener() {
@Override
public void onNativeAdLoaded(MaxNativeAdView nativeAdView, MaxAd ad) {
// Destroy previous ad if exists
if (nativeAd != null) nativeAdLoader.destroy(nativeAd);
// Store the new ad to allow destroying it later
nativeAd = ad;
// Add ad view to container
containerAdView.removeAllViews();
containerAdView.addView(nativeAdView);
}
@Override
public void onNativeAdLoadFailed(String adUnitId, MaxError error) {}
@Override
public void onNativeAdClicked(MaxAd ad) {}
});
Load an ad
Create the TeadsMediationSettings, then add the settings to the local extra parameters
- Kotlin
- Java
val settingsEncoded = TeadsMediationSettings.Builder()
.enableDebug()
.build().toJsonEncoded()
nativeAdLoader.setLocalExtraParameter("teadsSettings", settingsEncoded)
nativeAdLoader.loadAd(createNativeAdView())
String settingsEncoded = new TeadsMediationSettings.Builder()
.enableDebug()
.build().toJsonEncoded();
nativeAdLoader.setLocalExtraParameter("teadsSettings", settingsEncoded);
nativeAdLoader.loadAd(createNativeAdView());
Mediation settings
Find the full settings list in Settings Configuration — TeadsMediationSettings.
Checklist
- ✅ Ensure Brand Safety is enabled
- ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- ✅ Comply with app-ads.txt
- ✅ Implement proper error handling
- ✅ Enable ad view resizing for Media
- ✅ Test different PIDs with various ad formats and sizes. See Test PIDs and Configurations