Banner Ads
Banner ads are rectangular ads that occupy a portion of your app's layout. They can refresh automatically and stay on screen while users interact with your app.
Each ad format uses a Zone ID to identify the ad placement. Zone IDs are configured in the Empower dashboard.
Note: All ad status listeners are optional. The SDK handles ad loading and display automatically. Use listeners only if you need to track ad states for analytics, UI updates, or custom logic.
Supported Sizes
| Size | Description |
|---|---|
| 320x50 | Standard Banner |
| 320x100 | Large Banner |
| 300x250 | Medium Rectangle |
XML Layout Setup
Add a container for the banner in your layout:
<!-- activity_main.xml --><FrameLayoutandroid:id="@+id/bannerContainer"android:layout_width="match_parent"android:layout_height="wrap_content" />
Loading a Banner Ad
- Kotlin
- Java
import net.empower.mobile.ads.api.EMAManagerclass MainActivity : AppCompatActivity() {private lateinit var bannerContainer: FrameLayoutoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)bannerContainer = findViewById(R.id.bannerContainer)EMAManager.loadBannerAd(descriptor = this,zoneId = "YOUR_BANNER_ZONE_ID",bannerContainer = bannerContainer)}}
Listening to Banner Status (Optional)
If you need to track banner status for analytics or UI updates:
- Kotlin
- Java
EMAManager.loadBannerAd(descriptor = this,zoneId = "YOUR_BANNER_ZONE_ID",bannerContainer = bannerContainer,listener = object : AdStatusListener {override fun bannerStatusChanged(status: AdStatus, zoneId: String, adUnitId: String) {when (status) {AdStatus.READY -> { /* Banner is loaded and displayed */ }AdStatus.FAILED -> { /* Banner failed to load */ }AdStatus.WILL_LEAVE -> { /* User clicked the ad */ }else -> {}}}})
Jetpack Compose
For apps using Jetpack Compose, use the EmpowerBannerAd composable:
import androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.LocalLifecycleOwnerimport net.empower.mobile.ads.api.compose.EmpowerBannerAd@Composablefun BannerAdSection(modifier: Modifier = Modifier) {val context = LocalContext.currentval lifecycleOwner = LocalLifecycleOwner.currentEmpowerBannerAd(modifier = modifier,zoneId = "YOUR_BANNER_ZONE_ID",context = context,lifecycleOwner = lifecycleOwner)}
RecyclerView Usage (Pause & Resume)
When displaying banner ads inside a RecyclerView, pause and resume the banner's refresh timer based on item visibility to prevent unnecessary ad refreshes while off-screen.
- Kotlin
- Java
override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) {super.onViewAttachedToWindow(holder)if (holder is BannerViewHolder) {holder.zoneId?.let { EMAManager.resumeBannerZone(activity, it) }}}override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {super.onViewDetachedFromWindow(holder)if (holder is BannerViewHolder) {holder.zoneId?.let { EMAManager.pauseBannerZone(activity, it) }}}
| Method | Description |
|---|---|
pauseBannerZone(activity, zoneId) | Pauses the banner refresh timer when the item scrolls off-screen |
resumeBannerZone(activity, zoneId) | Resumes the banner refresh timer when the item scrolls back on-screen |
Custom Targeting Parameters
Pass custom targeting parameters for more relevant ads:
- Kotlin
- Java
EMAManager.loadBannerAd(descriptor = this,zoneId = "YOUR_BANNER_ZONE_ID",bannerContainer = bannerContainer,customParameters = "category=sports§ion=news")
Ad Status Reference
| Status | Description |
|---|---|
READY | Banner is loaded and displayed |
FAILED | Banner failed to load |
WILL_LEAVE | User clicked the ad (leaving app) |