Class AdManager
The entry point of the Codename One advertising API. It holds the active
AdProvider and exposes the lifecycle integrations (interstitial-on-transition
and app open ads) that build on the Codename One form and application
lifecycle.
A provider is supplied by an ad library and registered once at startup. Each
library exposes a static install() method that registers its provider, so
wiring AdMob is a single line:
public void init(Object context) {
AdMobProvider.install();
AdManager.initialize(new AdConfig(), ready -> AdConsent.requestConsent(null));
}
Any object implementing AdProvider can be registered with
registerProvider(AdProvider) directly, so third party ad networks and
mediation layers plug in without changing the framework or the build.
When no provider is registered the API degrades gracefully: format support
reports false and loads fail with AdError.CODE_UNSUPPORTED instead of
throwing.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbindInterstitialOnTransition(InterstitialAd ad, int minIntervalMillis) Shows the supplied interstitial automatically on screen transitions, no more often thanminIntervalMillis.static voidLoads the supplied app open ad and lets the provider show it automatically whenever the application returns to the foreground.static AdConfigThe configuration passed toinitialize(AdConfig, AdCallback), or null if it has not been called.static AdProviderThe active ad provider, or null when none is registered or the registered provider is unsupported on this platform.static voidinitialize(AdConfig cfg, AdCallback<Boolean> onComplete) Initializes the active provider's SDK.static booleanTrue onceinitialize(AdConfig, AdCallback)has completed successfully.static booleanisSupported(AdFormat format) True when the active provider supports the given format.static voidRegisters the ad provider to use, replacing any previously registered provider.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
registerProvider
Registers the ad provider to use, replacing any previously registered provider. Normally called by a provider's static
install()method.Parameters
p: the provider to use
-
getProvider
The active ad provider, or null when none is registered or the registered provider is unsupported on this platform. -
getConfig
The configuration passed toinitialize(AdConfig, AdCallback), or null if it has not been called. -
isSupported
True when the active provider supports the given format.
Parameters
format: the format to query
-
initialize
Initializes the active provider's SDK. The callback fires when initialization completes (immediately with
Boolean.FALSEwhen no provider is registered).Parameters
cfg: the global ad configuration, must not be nullonComplete: invoked with the readiness flag, may be null
-
isInitialized
public static boolean isInitialized()True onceinitialize(AdConfig, AdCallback)has completed successfully. -
bindInterstitialOnTransition
Shows the supplied interstitial automatically on screen transitions, no more often than
minIntervalMillis.The manager loads the first ad, shows it when a transition occurs and the interval has elapsed, and preloads the next one when the ad is dismissed. Any
AdListeneryou set on the ad is still notified.Parameters
ad: the interstitial to show on transitionsminIntervalMillis: minimum time between two shown ads
-
enableAppOpenAds
Loads the supplied app open ad and lets the provider show it automatically whenever the application returns to the foreground.
Parameters
ad: the app open ad to manage
-