Android
The Ezoic Ads SDK for Android lets you display banner ads in native Android apps. The SDK initializes Ezoic configuration, Prebid, Google Ad Manager, and consent handling from one integration point.
Requirements 🔗
- Android SDK 24 or higher
- Android Gradle Plugin 8.0 or higher
- Kotlin 1.9 or higher
- Google Mobile Ads application ID
Installation 🔗
Add the Ezoic Ads SDK dependency to your app module:
dependencies {
implementation("com.ezoic.sdk:ezoic-ads-sdk:1.0.0")
}
The SDK depends on Google Mobile Ads and Prebid Mobile. Make sure your project resolves dependencies from Google's Maven repository and Maven Central.
Initialize the SDK 🔗
Initialize the SDK from your Application class or main Activity before loading ads.
import android.app.Application
import android.util.Log
import com.ezoic.ads.sdk.core.EzoicAds
import com.ezoic.ads.sdk.core.EzoicConfiguration
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val config = EzoicConfiguration(
domain = "example.com",
debugEnabled = false,
testMode = false
)
EzoicAds.instance.initialize(this, config) { result ->
result.onSuccess {
Log.d("Ezoic", "SDK initialized")
}.onFailure { error ->
Log.e("Ezoic", "Initialization failed: $error")
}
}
}
}
domain must match the domain configured for your site in Ezoic.
Add a Banner Ad 🔗
Create an EzoicBannerView, add it to your layout, and call loadAd() after the SDK is initialized.
import android.os.Bundle
import android.util.Log
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import com.ezoic.ads.sdk.adunits.EzoicBannerView
import com.ezoic.ads.sdk.adunits.EzoicBannerViewListener
import com.ezoic.ads.sdk.core.EzoicError
class MainActivity : AppCompatActivity(), EzoicBannerViewListener {
private lateinit var bannerView: EzoicBannerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bannerView = EzoicBannerView(this, 12345)
bannerView.listener = this
val container = findViewById<FrameLayout>(R.id.banner_container)
container.addView(bannerView)
bannerView.loadAd("300x250")
}
override fun onBannerLoaded(bannerView: EzoicBannerView) {
Log.d("Ezoic", "Banner loaded")
}
override fun onBannerLoadFailed(bannerView: EzoicBannerView, error: EzoicError) {
Log.e("Ezoic", "Banner failed: ${error.message}")
}
override fun onDestroy() {
bannerView.destroy()
super.onDestroy()
}
}
Replace 12345 with your Ezoic ad unit identifier. The SDK fetches the Google Ad Manager ad unit, Prebid configuration, supported sizes, targeting values, and refresh interval from Ezoic servers.
Banner Sizes 🔗
You can load ads with an adaptive default size, a typed size, one size string, or a list of size strings.
bannerView.loadAd()
bannerView.loadAd(EzoicBannerSize.MediumRectangle)
bannerView.loadAd("300x250")
bannerView.loadAd(listOf("300x250", "320x50"))
Common sizes include:
EzoicBannerSize.Banner: 320x50EzoicBannerSize.LargeBanner: 320x100EzoicBannerSize.MediumRectangle: 300x250EzoicBannerSize.FullBanner: 468x60EzoicBannerSize.Leaderboard: 728x90EzoicBannerSize.Custom(width, height): custom dimensions
AndroidManifest.xml 🔗
Add your Google Mobile Ads application ID to AndroidManifest.xml:
In most Ezoic mobile app integrations, this app ID is provided by Ezoic and can be found in your Ezoic dashboard. Use the value assigned to your app unless your Ezoic representative gives you a different Google Mobile Ads application ID.
<manifest>
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX" />
</application>
</manifest>
If your app targets Android 12 or higher and uses the advertising ID, add the advertising ID permission:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
Privacy and Consent 🔗
The SDK can automatically read consent signals from SharedPreferences when they are set by a consent management platform.
- TCF v2 consent is read from
IABTCF_*keys. - GPP consent is read from
IABGPP_*keys. - US Privacy consent is read from the standard IAB privacy key.
You can also set consent manually:
EzoicAds.instance.setGDPRConsent(
applies = true,
consentString = "TCF_CONSENT_STRING"
)
EzoicAds.instance.setGPPConsent(
gppString = "GPP_STRING",
sectionIds = "7"
)
EzoicAds.instance.setSubjectToCOPPA(true)
Pageview Tracking 🔗
The SDK automatically tracks pageviews for standard Activity, Fragment, and view-hosted Navigation components after initialization.
If your app uses Compose Navigation, opt in with your NavController:
val navController = rememberNavController()
EzoicAds.instance.TrackNavigation(navController)
For WebView-heavy apps, use EzoicWebViewClient so page loads are tracked as pageviews:
webView.webViewClient = EzoicWebViewClient()
You can also track a pageview manually:
EzoicAds.instance.trackPageview()
Java Compatibility 🔗
The Android SDK is written in Kotlin, but the public API is designed for Java interoperability. Java apps can use the EzoicConfiguration.Builder, callback interfaces, Java-friendly banner size constants, and EzoicBannerViewAdapter.
Troubleshooting 🔗
SDK Not Initializing 🔗
- Confirm the configured domain matches your Ezoic dashboard.
- Confirm the app has network access.
- Enable
debugEnabled = trueand check Logcat forEzoicAdslogs.
Ads Not Loading 🔗
- Initialize the SDK before calling
loadAd(). - Confirm the Ezoic ad unit identifier is configured in Ezoic.
- Confirm the Google Mobile Ads application ID is present in
AndroidManifest.xml. - Check consent configuration if traffic is subject to privacy regulations.