AppOpenAdController

open class AppOpenAdController(context: Context, val buildInfoRepository: BuildInfoRepository, dispatchers: DispatcherProvider, adMobAppIdDataSource: AdMobAppIdDataSource = ManifestAdMobAppIdDataSource(context = context, dispatchers = dispatchers), adsSdkInitializer: AdsSdkInitializer = AdsSdkInitializer.Default, adsSettingsRepository: AdsSettingsRepository)(source)

Configures and displays App Open ads. Mutable lifecycle state uses the injected main dispatcher.

It checks user preferences stored in AdsSettingsRepository to determine whether ads should be shown and manages the lifecycle of an AppOpenAd instance.

Constructors

Link copied to clipboard
constructor(context: Context, buildInfoRepository: BuildInfoRepository, dispatchers: DispatcherProvider, adMobAppIdDataSource: AdMobAppIdDataSource = ManifestAdMobAppIdDataSource(context = context, dispatchers = dispatchers), adsSdkInitializer: AdsSdkInitializer = AdsSdkInitializer.Default, adsSettingsRepository: AdsSettingsRepository)

Properties

Functions

Link copied to clipboard
fun close()

Stops preference observation and drops later SDK callbacks when the owning graph closes.

Link copied to clipboard
suspend fun ensureAdsSdkInitialized(disableNativeValidator: Boolean = false): Boolean

Initializes the SDK once and publishes readiness. Ad loaders must wait for true; loading before initialization throws. The SDK initializes on IO, as Google asks for it to run off the main thread; the preference reads need no switch, since DataStore is main-safe.

Link copied to clipboard
suspend fun initializeAds(appOpenUnitId: String, disableNativeValidator: Boolean = false)

Initializes ads from the host-manifest AdMobAppIdDataSource and observes the shared AdsSettingsRepository.adsEnabled, so enabling ads later can initialize the SDK without a process restart. Missing or invalid app IDs skip initialization; no fallback publisher ID is supplied.

Link copied to clipboard
fun showAdIfAvailable(activity: Activity, scope: CoroutineScope)

Displays an ad if one has been loaded.