AppOpenAdManager
is just a simple wrapper to handle the new AppOpenAd
Format by Google AdMob.
If you look at the tutorial, you'll see the detailed guide to create a Helper Class
to manage AppOpenAd
.
Gradle:
implementation 'com.lazygeniouz:aoa_manager:$latest_version'
val configs = Configs(InitialDelay.NONE, adUnitId, adRequest, showInActivity)
val adManager = AppOpenAdManager.get(application, configs)
adManager.setAppOpenAdListener(appOpenAdlistener)
adManager.setAdTransition(R.anim.enterAnim, R.anim.exitAnim)
adManager.setOnPaidEventListener(paidEventListener)
adManager.showAdWithDelay(false)
adManager.setImmersiveMode(true)
adManager.loadAppOpenAd()
The arguments for the static method get
are:
-
@NonNull application: Application
Your class extendingandroid.app.Application
-
@NonNull configs: Configs
(Optional)
You can pass aConfigs
object which is adata
class to pass relevant options.
Relevant options are:-
@NonNull initialDelay: InitialDelay
You can specify an Initial Delay to load & display the Ad for the first time.
If you do not need a delay, simple passInitialDelay.NONE
But it is a good practise to allow the user to first explore the App &
therefore 1 Day should be fine which is also the Default if you passInitialDelay()
-
adUnitId: String
YouradUnitId
(Optional for Testing) Default is a Test AdUnitId -
adRequest: AdRequest
(Optional) If you have a customised AdRequest -
showOnColdStart: Boolean
(Optional) Show Ad as soon as it load on the first Cold start if true, this will ignore the Activities passed in the [showInActivities] -
showOnCondition: (() -> Boolean)
(Optional) Show the AppOpenAd only when a specific condition is met. AppOpenAd will be shown only when this block returnstrue
. -
showInActivities: Class<out Activity>
(Optional) If you want to show the Ad only in specific Activities (e.g: SplashActivity).
See: this issue & the Example App for more info.
-
Other available methods:
-
getAppOpenAd: AppOpenAd?
: Returns theAppOpenAd
instance, can be null. -
clearAdInstance(): Unit
: Sets theAppOpenAd
instance tonull
if it is not. -
isAdAvailable(): Boolean
: Returnstrue
if a validAppOpenAd
is available -
setImmersiveMode(Boolean): Unit
: Sets whether to show theAdOpenAd
in immersive mode. -
showAdWithDelay(Boolean): Unit
: Delays showing theAdOpenAd
by 1 second if true. -
showAdWithDelay(Long): Unit
: Delays showing theAdOpenAd
by the provided time in milliseconds. -
setAdTransition(Int, Int): Unit
: Use an activity animation when the Ad is shown, similar toActivity.overridePendingTransition
orActivity.overrideActivityTransition
. -
getAdListener(): AppOpenAdListener?
: Returns the currently set Ad Listener, can be null. -
setAppOpenAdListener(listener: AppOpenAdListener)
:
There are several callbacks with respect to the AppOpenAd.onAdLoaded()
= Invoked when the Ad is loaded successfully.onAdFailedToLoad(LoadAdError)
= Invoked when the Ad failed to load with supplied LoadAdError.onAdWillShow()
= Invoked before the Ad is shown, a default delay of 1000ms or value provided.onAdShown()
= Invoked when the Ad is shownonAdDismissed()
= Invoked after the Ad is dismissed from the screenonAdShowFailed(AdError)
= Invoked when there was an error showing the Ad with supplied AdError
-
setOnPaidEventListener(listener: OnPaidEventListener)
:onPaidEvent(AdValue)
= Called when an ad is estimated to have earned money.AdValue
= Contains information about the monetary value earned from an ad.
-
getPaidEventListener(): OnPaidEventListener?
: Returns the currently set Ad's PaidEventListener, can be null..