BannerAdHandler

actual class BannerAdHandler(activity: Any?)
expect class BannerAdHandler(activity: Any?)

A BannerAdHandler creates landscape ads that cover part of the host app screen.

This class is responsible for loading and managing the state of a banner advertisement provided by Google Mobile Ads. It requires an Android Activity for its operations.

Usage Example:

// In your Composable function or where you have access to an Activity:
val activity = LocalContext.current as Activity

// Instantiate the BannerAdHandler
val adHandler = rememberBannerAd(activity = activity)

// Load the Ad (typically in a LaunchedEffect or similar)
LaunchedEffect(Unit) {
adHandler.load(
adUnitId = "YOUR_ADMOB_BANNER_AD_UNIT_ID", // Replace with your actual Ad Unit ID
adSize = AdSize.BANNER, // Or any other desired AdSize
onLoad = {
// Ad loaded successfully
println("Banner Ad loaded!")
},
onFailure = { exception ->
// Ad failed to load
println("Banner Ad failed to load: ${exception.message}")
},
onDismissed = {
// Ad was dismissed (not typical for banners, but callback exists)
println("Banner Ad dismissed.")
},
onShown = {
// Ad is now visible on screen
println("Banner Ad shown.")
},
onImpression = {
// Ad impression has been recorded
println("Banner Ad impression recorded.")
},
onClick = {
// User clicked on the ad
println("Banner Ad clicked.")
}
)
}

// Display the ad in your Composable UI
if (adHandler.state == AdState.Loaded) { // Or handle other states like Loading, Error
BannerAd(adHandler)
}

Parameters

activity

The Android Activity required for displaying the ad. On platforms other than Android, this parameter might be unused or expect a platform-specific equivalent.

actual class BannerAdHandler(activity: Any?)

Constructors

Link copied to clipboard
actual constructor(activity: Any?)
expect constructor(activity: Any?)
actual constructor(activity: Any?)

Properties

Link copied to clipboard
actual val adSize: AdSize

Holds the active AdSize of the BannerAdHandler

expect val adSize: AdSize

Holds the active AdSize of the BannerAdHandler

actual val adSize: AdSize

Holds the active AdSize of the BannerAdHandler

bannerView
Link copied to clipboard
Link copied to clipboard
actual val state: AdState

Determines the AdState of the BannerAdHandler

expect val state: AdState

Determines the AdState of the BannerAdHandler

actual val state: AdState

Determines the AdState of the BannerAdHandler

Functions

Link copied to clipboard
@RequiresPermission(value = "android.permission.INTERNET")
actual fun load(adUnitId: String, adSize: AdSize, onLoad: () -> Unit, onFailure: (Exception) -> Unit, onDismissed: () -> Unit, onShown: () -> Unit, onImpression: () -> Unit, onClick: () -> Unit)
expect fun load(adUnitId: String = AdUnitId.BANNER_DEFAULT, adSize: AdSize = AdSize.FULL_BANNER, onLoad: () -> Unit = {}, onFailure: (Exception) -> Unit = {}, onDismissed: () -> Unit = {}, onShown: () -> Unit = {}, onImpression: () -> Unit = {}, onClick: () -> Unit = {})

Loads an Banner Ad. Note: Make all calls to the Mobile Ads SDK on the main thread.

actual fun load(adUnitId: String, adSize: AdSize, onLoad: () -> Unit, onFailure: (Exception) -> Unit, onDismissed: () -> Unit, onShown: () -> Unit, onImpression: () -> Unit, onClick: () -> Unit)