Installation
Installation Methods
- Gradle
- Manual
Using Gradle/Maven
- Add the Teads repository to your
project/build.gradle: - Add the Teads SDK dependency to your
app/build.gradle: - Sync your project
project/build.gradle
repositories {
maven { url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod" }
maven {
// Mandatory for Huawei device compatibility
url "https://developer.huawei.com/repo/"
}
}
app/build.gradle
dependencies {
implementation("tv.teads.sdk.android:sdk:6.2.0@aar") {
transitive = true
}
}
Huawei Device Compatibility
For Huawei devices, the Huawei repository is mandatory and included in the configuration above.
Download AAR File
For manual installation, you can download the latest TeadsSDK.aar:
- Download the latest TeadsSDK.aar from the Maven repository
- Copy it to your app's
libsfolder - Add to your
app/build.gradle:
dependencies {
implementation files('libs/sdk-6.2.0.aar')
}
Sample Application
The official Teads SDK sample application demonstrates best practices and integration examples.
GitHub Repository: TeadsSDK-android
SDK Initialization
Initialize the Teads SDK as early as possible in your app's lifecycle:
- Kotlin
- Java
import tv.teads.sdk.TeadsSDK
// Initialize the SDK with your partner key
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
TeadsSDK.configure(applicationContext, "YOUR_PARTNER_KEY")
// Enable test mode for development
if (BuildConfig.DEBUG) {
TeadsSDK.testMode = true
TeadsSDK.testLocation = "us" // Optional: Test specific geolocations
}
}
}
import tv.teads.sdk.TeadsSDK;
import com.outbrain.OBSDK.OutbrainException;
// Initialize the SDK with your partner key
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
TeadsSDK.INSTANCE.configure(getApplicationContext(), "YOUR_PARTNER_KEY");
} catch (OutbrainException e) {
// Handle configuration error
}
// Enable test mode for development
if (BuildConfig.DEBUG) {
TeadsSDK.INSTANCE.setTestMode(true);
TeadsSDK.INSTANCE.setTestLocation("us"); // Optional: Test specific geolocations
}
}
}
Important: Calling the method the TeadsSDK.configure with your YOUR_PARTNER_KEY is mandatory when using the Feed or Recommendations placements. Otherwise, you can skip this part.
Implementation Samples
For complete working examples and sample applications, refer to our public GitHub repositories:
- Android Sample App - Complete Android implementation with all placement types
These repositories contain:
- Full working applications demonstrating all placement types
- Best practices and common integration patterns
Settings
Find the full settings list for each placement in the Settings Configuration.
Event Handling
Comprehensive Event Handling
- Kotlin
- Java
class ComprehensiveEventHandler : TeadsAdPlacementEventsDelegate {
override fun onPlacementEvent(
placement: TeadsAdPlacement<*, *>,
event: TeadsAdPlacementEventName,
data: Map<String, Any>?
) {
Log.d("TeadsSDK", "Event: $event from $placement with data $data")
when (event) {
TeadsAdPlacementEventName.LOADED -> {
// Placement is requested to load the ad
Log.d("TeadsSDK", "Content fully loaded")
}
TeadsAdPlacementEventName.READY -> {
// Ad is loaded and ready to display
Log.d("TeadsSDK", "Ad is ready to be displayed")
}
TeadsAdPlacementEventName.RENDERED -> {
// Ad has been rendered on screen
Log.d("TeadsSDK", "Ad has been rendered")
}
// Interstitial events
TeadsAdPlacementEventName.WILL_PRESENT -> {
// Fired right before the fullscreen interstitial is presented
Log.d("TeadsSDK", "Interstitial will present")
}
TeadsAdPlacementEventName.PRESENTED -> {
// Fired when the fullscreen interstitial has been presented
Log.d("TeadsSDK", "Interstitial presented")
}
TeadsAdPlacementEventName.WILL_DISMISS -> {
// Fired right before the fullscreen interstitial is dismissed
Log.d("TeadsSDK", "Interstitial will dismiss")
}
TeadsAdPlacementEventName.DISMISSED -> {
// Fired when the fullscreen interstitial has been dismissed by the user
Log.d("TeadsSDK", "Interstitial dismissed")
}
TeadsAdPlacementEventName.VIEWED -> {
// Ad has met IAB viewability standards
Log.d("TeadsSDK", "Ad has met viewability criteria")
}
TeadsAdPlacementEventName.CLICKED -> {
// User clicked on the ad
// SDK handles URL opening automatically
Log.d("TeadsSDK", "User clicked on ad")
}
TeadsAdPlacementEventName.CLICKED_ORGANIC -> {
// User clicked on organic content (Feed placement)
val url = data?.get("url") as? String
Log.d("TeadsSDK", "User clicked on organic content: $url")
url?.let {
// Open in browser or in-app browser
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(it))
startActivity(intent)
}
}
TeadsAdPlacementEventName.FAILED -> {
// Ad failed to load
// Show fallback content or hide ad container
val reason = data?.get("reason") as? String
Log.e("TeadsSDK", "Ad failed to load: $reason")
}
TeadsAdPlacementEventName.PLAY -> {
// Video started playing
Log.d("TeadsSDK", "Video started playing")
}
TeadsAdPlacementEventName.PAUSE -> {
// Video paused
Log.d("TeadsSDK", "Video paused")
}
TeadsAdPlacementEventName.COMPLETE -> {
// Video completed
Log.d("TeadsSDK", "Video completed")
}
TeadsAdPlacementEventName.START_PLAY_AUDIO -> {
// Ad started playing audio
Log.d("TeadsSDK", "Ad started playing audio")
}
TeadsAdPlacementEventName.STOP_PLAY_AUDIO -> {
// Ad stopped playing audio
Log.d("TeadsSDK", "Ad stopped playing audio")
}
TeadsAdPlacementEventName.HEIGHT_UPDATED -> {
// Ad height changed (useful for dynamic layouts)
// This is the height your ad container must match
val height = data?.get("height") as? Int
Log.d("TeadsSDK", "Ad height updated to: $height")
}
else -> {
Log.d("TeadsSDK", "Other event: $event")
}
}
}
}
public class ComprehensiveEventHandler implements TeadsAdPlacementEventsDelegate {
@Override
public void onPlacementEvent(
TeadsAdPlacement<?, ?> placement,
TeadsAdPlacementEventName event,
Map<String, ?> data
) {
Log.d("TeadsSDK", "Event: " + event + " from " + placement + " with data " + data);
if (event == TeadsAdPlacementEventName.LOADED) {
// Placement is requested to load the ad
Log.d("TeadsSDK", "Content fully loaded");
} else if (event == TeadsAdPlacementEventName.READY) {
// Ad is loaded and ready to display
Log.d("TeadsSDK", "Ad is ready to be displayed");
} else if (event == TeadsAdPlacementEventName.RENDERED) {
// Ad has been rendered on screen
Log.d("TeadsSDK", "Ad has been rendered");
// Interstitial events
} else if (event == TeadsAdPlacementEventName.WILL_PRESENT) {
// Fired right before the fullscreen interstitial is presented
Log.d("TeadsSDK", "Interstitial will present");
} else if (event == TeadsAdPlacementEventName.PRESENTED) {
// Fired when the fullscreen interstitial has been presented
Log.d("TeadsSDK", "Interstitial presented");
} else if (event == TeadsAdPlacementEventName.WILL_DISMISS) {
// Fired right before the fullscreen interstitial is dismissed
Log.d("TeadsSDK", "Interstitial will dismiss");
} else if (event == TeadsAdPlacementEventName.DISMISSED) {
// Fired when the fullscreen interstitial has been dismissed by the user
Log.d("TeadsSDK", "Interstitial dismissed");
} else if (event == TeadsAdPlacementEventName.VIEWED) {
// Ad has met IAB viewability standards
Log.d("TeadsSDK", "Ad has met viewability criteria");
} else if (event == TeadsAdPlacementEventName.CLICKED) {
// User clicked on the ad
// SDK handles URL opening automatically
Log.d("TeadsSDK", "User clicked on ad");
} else if (event == TeadsAdPlacementEventName.CLICKED_ORGANIC) {
// User clicked on organic content (Feed placement)
String url = data != null ? (String) data.get("url") : null;
Log.d("TeadsSDK", "User clicked on organic content: " + url);
if (url != null) {
// Open in browser or in-app browser
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
} else if (event == TeadsAdPlacementEventName.FAILED) {
// Ad failed to load
// Show fallback content or hide ad container
String reason = data != null ? (String) data.get("reason") : null;
Log.e("TeadsSDK", "Ad failed to load: " + reason);
} else if (event == TeadsAdPlacementEventName.PLAY) {
// Video started playing
Log.d("TeadsSDK", "Video started playing");
} else if (event == TeadsAdPlacementEventName.PAUSE) {
// Video paused
Log.d("TeadsSDK", "Video paused");
} else if (event == TeadsAdPlacementEventName.COMPLETE) {
// Video completed
Log.d("TeadsSDK", "Video completed");
} else if (event == TeadsAdPlacementEventName.START_PLAY_AUDIO) {
// Ad started playing audio
Log.d("TeadsSDK", "Ad started playing audio");
} else if (event == TeadsAdPlacementEventName.STOP_PLAY_AUDIO) {
// Ad stopped playing audio
Log.d("TeadsSDK", "Ad stopped playing audio");
} else if (event == TeadsAdPlacementEventName.HEIGHT_UPDATED) {
// Ad height changed (useful for dynamic layouts)
// This is the height your ad container must match
Integer height = data != null ? (Integer) data.get("height") : null;
Log.d("TeadsSDK", "Ad height updated to: " + height);
} else {
Log.d("TeadsSDK", "Other event: " + event);
}
}
}
The SDK automatically handles opening the click URL in the CLICKED event. Do not implement URL navigation in this event handler — doing so will result in the browser opening twice.
Use this event only for tracking/analytics purposes.
Best Practices
1. Placement Lifecycle Management
Media, Media Native and Interstitial placements
Call clean() method for Media, Media Native and Interstitial placements when they're no longer needed to prevent memory leaks:
- Kotlin
- Java
class ContentActivity : AppCompatActivity(), TeadsAdPlacementEventsDelegate {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ... setup your placements
}
override fun onDestroy() {
super.onDestroy()
when (placement) {
is TeadsAdPlacementMedia -> placement.clean()
is TeadsAdPlacementMediaNative -> placement.clean()
is TeadsAdPlacementInterstitial -> placement.clean()
}
}
}
public class ContentActivity extends AppCompatActivity implements TeadsAdPlacementEventsDelegate {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ... setup your placements
}
@Override
protected void onDestroy() {
super.onDestroy();
if (placement instanceof TeadsAdPlacementMedia) {
((TeadsAdPlacementMedia) placement).clean();
} else if (placement instanceof TeadsAdPlacementMediaNative) {
((TeadsAdPlacementMediaNative) placement).clean();
} else if (placement instanceof TeadsAdPlacementInterstitial) {
((TeadsAdPlacementInterstitial) placement).clean();
}
}
}
Feed and Recommendations placements
For Feed and Recommendation placements, ensure you load only one ad instance per screen.
To prevent redundant ad requests during view recycling (RecyclerView) or recomposition (LazyList), cache the loaded ad by holding a strong lifecycle aware reference to it.
2. Error Handling
Always implement proper error handling:
- Kotlin
- Java
// Handle errors through the delegate
override fun onPlacementEvent(
placement: TeadsAdPlacement<*, *>,
event: TeadsAdPlacementEventName,
data: Map<String, Any>?
) {
if (event == TeadsAdPlacementEventName.FAILED) {
// Ad failed to load
// Show fallback content or hide ad container
val reason = data?.get("reason") as? String
Log.e("TeadsSDK", "Ad failed to load: $reason")
}
}
// Handle errors through the delegate
@Override
public void onPlacementEvent(
TeadsAdPlacement<?, ?> placement,
TeadsAdPlacementEventName event,
Map<String, ?> data
) {
if (event == TeadsAdPlacementEventName.FAILED) {
// Ad failed to load
// Show fallback content or hide ad container
String reason = data != null ? (String) data.get("reason") : null;
Log.e("TeadsSDK", "Ad failed to load: " + reason);
}
}
3. Testing
Use test mode during development:
- Kotlin
- Java
// Enable test mode for development
if (BuildConfig.DEBUG) {
TeadsSDK.testMode = true
TeadsSDK.testLocation = "us" // Optional: Test specific geolocations
}
// Enable test mode for development
if (BuildConfig.DEBUG) {
TeadsSDK.INSTANCE.setTestMode(true);
TeadsSDK.INSTANCE.setTestLocation("us"); // Optional: Test specific geolocations
}
Next Steps
- Review the Migration Guide for Teads Users
- Review the Migration Guide for Outbrain Users
- Learn about Privacy & Compliance
For additional support, see Support