public final class AdManager
- Object
- 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.
Methods
Inherited methods
Method details
registerProvider
public static void registerProvider(AdProvider p)install() method.Parameters
pAdProvider- the provider to use
getProvider
public static AdProvider getProvider()getConfig
public static AdConfig getConfig()initialize(AdConfig, AdCallback), or null
if it has not been called.isSupported
public static boolean isSupported(AdFormat format)Parameters
formatAdFormat- the format to query
initialize
public static void initialize(AdConfig cfg, AdCallback<Boolean> onComplete)Boolean.FALSE when no
provider is registered).Parameters
cfgAdConfig- the global ad configuration, must not be null
onCompleteAdCallback<Boolean>- invoked with the readiness flag, may be null
isInitialized
public static boolean isInitialized()initialize(AdConfig, AdCallback) has completed successfully.bindInterstitialOnTransition
public static void bindInterstitialOnTransition(InterstitialAd ad, int minIntervalMillis)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 AdListener you set on the ad is still notified.
Parameters
adInterstitialAd- the interstitial to show on transitions
minIntervalMillisint- minimum time between two shown ads
enableAppOpenAds
public static void enableAppOpenAds(AppOpenAd ad)Parameters
adAppOpenAd- the app open ad to manage