Class AdConsent
Manages user privacy consent for advertising. On modern platforms collecting consent is mandatory before personalized ads can be served: in the EEA/UK the GDPR consent form must be shown (the provider wraps Google's User Messaging Platform or an equivalent), and on iOS the App Tracking Transparency prompt must be presented to access the advertising identifier.
The recommended flow is: initialize the AdManager, request consent, then
load ads only once consent has been resolved:
AdManager.initialize(new AdConfig(), ok ->
AdConsent.requestConsent(status -> {
if (AdConsent.canRequestAds()) {
interstitial.load();
}
}));
When no provider is registered consent calls resolve immediately to
STATUS_NOT_REQUIRED.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConsent is not required for this user (e.g. outside the EEA).static final intConsent was obtained.static final intConsent is required and has not yet been obtained.static final intConsent status is unknown (consent has not been requested yet). -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanTrue when there is enough consent to request ads.static intThe current consent status without triggering a new request.static voidrequestConsent(AdCallback<Integer> onComplete) Gathers consent if required, presenting the consent form and (on iOS) the App Tracking Transparency prompt as needed.static voidreset()Clears stored consent.
-
Field Details
-
STATUS_UNKNOWN
public static final int STATUS_UNKNOWNConsent status is unknown (consent has not been requested yet).- See Also:
-
STATUS_REQUIRED
public static final int STATUS_REQUIREDConsent is required and has not yet been obtained.- See Also:
-
STATUS_NOT_REQUIRED
public static final int STATUS_NOT_REQUIREDConsent is not required for this user (e.g. outside the EEA).- See Also:
-
STATUS_OBTAINED
public static final int STATUS_OBTAINEDConsent was obtained.- See Also:
-
-
Method Details
-
requestConsent
Gathers consent if required, presenting the consent form and (on iOS) the App Tracking Transparency prompt as needed. The callback receives one of the
STATUS_*constants on the EDT when the flow completes.Parameters
onComplete: invoked with the resulting consent status, may be null
-
canRequestAds
public static boolean canRequestAds()True when there is enough consent to request ads. When no provider is installed this returns true so the simulator placeholder flow works. -
getConsentStatus
public static int getConsentStatus()The current consent status without triggering a new request. -
reset
public static void reset()Clears stored consent. Intended for testing the consent flow only.
-