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

SizeDescription
320x50Standard Banner
320x100Large Banner
300x250Medium Rectangle

XML Layout Setup

Add a container for the banner in your layout:

<!-- activity_main.xml -->
<FrameLayout
android:id="@+id/bannerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Loading a Banner Ad

import net.empower.mobile.ads.api.EMAManager
class MainActivity : AppCompatActivity() {
private lateinit var bannerContainer: FrameLayout
override 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:

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.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import net.empower.mobile.ads.api.compose.EmpowerBannerAd
@Composable
fun BannerAdSection(modifier: Modifier = Modifier) {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
EmpowerBannerAd(
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.

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) }
}
}
MethodDescription
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:

EMAManager.loadBannerAd(
descriptor = this,
zoneId = "YOUR_BANNER_ZONE_ID",
bannerContainer = bannerContainer,
customParameters = "category=sports&section=news"
)

Ad Status Reference

StatusDescription
READYBanner is loaded and displayed
FAILEDBanner failed to load
WILL_LEAVEUser clicked the ad (leaving app)