Ad Formats
The Nexad Android SDK supports various ad formats to suit different application styles and user experiences. This page describes each format and provides implementation examples.
Native Ads
Native ads are designed to match the look and feel of your application. They use standard Android UI components that you can customize to blend in with your app's design.
Implementation Example
// Load native ad
NexadSDK.getInstance().loadNativeAd("native_placement", object : AdDataLoadCallback {
override fun onSuccess(ads: List<Ad>) {
if (ads.isNotEmpty()) {
// Create native ad view
val adView = NexadSDK.getInstance().createNativeAdView(context, "native_placement")
// Configure with ad data
adView.configure(ads[0])
// Add to container
containerView.addView(adView)
}
}
override fun onFailure(error: Exception) {
Log.e("NexadSDK", "Failed to load native ad: ${error.message}")
}
})
Chat Message Ads
Chat Message ads are designed to seamlessly integrate into conversational interfaces. They appear as part of the conversation flow and can be styled to match your chat UI.
Implementation Example
// Create chatbot context with relevant conversation information
val chatbotContext = ChatbotContext(
history = listOf(
"User: Can you recommend a good smartphone?",
"Bot: Sure, I can help with that. What's your budget?"
),
query = "I'm looking for a phone under $500 with good camera"
)
// Load chat message ad with context
NexadSDK.getInstance().LoadChatMessageEmbedAd(
chatbotContext = chatbotContext,
callback = object : GenericUILoadCallback<View> {
override fun onSuccess(views: List<View>) {
// Views are ready-to-use UI components to insert into your chat interface
for (view in views) {
chatContainer.addView(view)
}
}
override fun onFailure(error: Exception) {
Log.e("NexadSDK", "Failed to load chat message ad: ${error.message}")
}
},
style = AdViewStyle( // Optional: Customize the appearance
backgroundColor = Color.WHITE,
cornerRadius = 16f,
padding = Padding(12f, 8f, 12f, 8f),
textStyle = TextStyle(
titleColor = Color.parseColor("#333333"),
descriptionColor = Color.parseColor("#666666"),
titleTextSize = 16f,
descriptionTextSize = 14f
)
)
)
WebView Ads
WebView ads use Android's WebView component to display HTML content. They're useful for rich, interactive ad experiences that would be difficult to achieve with native UI components.
Implementation Example
// Load WebView ad
NexadSDK.getInstance().loadWebViewAd("webview_placement", object : AdDataLoadCallback {
override fun onSuccess(ads: List<Ad>) {
if (ads.isNotEmpty()) {
// Create WebView
val webView = WebView(context)
webView.settings.javaScriptEnabled = true
// Load ad markup
val adMarkup = ads[0].adMarkup?.adm
if (!adMarkup.isNullOrEmpty()) {
webView.loadData(adMarkup, "text/html", "UTF-8")
}
// Add to container
containerView.addView(webView)
}
}
override fun onFailure(error: Exception) {
Log.e("NexadSDK", "Failed to load WebView ad", error)
}
})
Modal Overlay Ads
Modal overlay ads display as full-screen overlays with a customizable native ad experience. They're perfect for natural breaks in your app flow.
Implementation Example
// Show a native modal ad
NexadSDK.getInstance().showNativeModalAd(
context = context,
callback = { success, error -> // Optional: Callback to handle success/failure
if (!success) {
// Handle error case
Toast.makeText(
context,
"Failed to show modal ad: ${error?.message}",
Toast.LENGTH_SHORT
).show()
}
},
style = AdViewStyle( // Optional: Customize the appearance
backgroundColor = Color.WHITE,
cornerRadius = 16f,
elevation = 8f,
padding = Padding(16f, 16f, 16f, 16f),
textStyle = TextStyle(
titleColor = Color.BLACK,
descriptionColor = Color.GRAY,
titleTextSize = 18f,
descriptionTextSize = 14f
)
)
)
Choosing the Right Ad Format
When deciding which ad format to use, consider:
- User Experience: Choose formats that feel natural in your app's context
- App Type:
- Chat applications work well with Chat Message ads
- Content-focused apps may benefit from native ads
- Interactive experiences can leverage WebView ads
- Performance: Native ads generally have better performance than WebView ads
- Customization Needs: If you need highly customized ads, native formats offer more flexibility
For more details on customizing the appearance of ads, see the Customization guide.