public final class AdConsent
- Object
- 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.
Fields
public static final int STATUS_UNKNOWN = 0 | Consent status is unknown (consent has not been requested yet). |
public static final int STATUS_REQUIRED = 1 | Consent is required and has not yet been obtained. |
public static final int STATUS_NOT_REQUIRED = 2 | Consent is not required for this user (e.g. outside the EEA). |
public static final int STATUS_OBTAINED = 3 | Consent was obtained. |
Methods
public static void requestConsent(AdCallback<Integer> onComplete) | Gathers consent if required, presenting the consent form and (on iOS) the App Tracking Transparency prompt as needed. |
public static boolean canRequestAds() | True when there is enough consent to request ads. |
public static int getConsentStatus() | The current consent status without triggering a new request. |
public static void reset() | Clears stored consent. |
Inherited methods
Field details
STATUS_UNKNOWN
public static final int STATUS_UNKNOWN = 0Consent status is unknown (consent has not been requested yet).
STATUS_REQUIRED
public static final int STATUS_REQUIRED = 1Consent is required and has not yet been obtained.
STATUS_NOT_REQUIRED
public static final int STATUS_NOT_REQUIRED = 2Consent is not required for this user (e.g. outside the EEA).
STATUS_OBTAINED
public static final int STATUS_OBTAINED = 3Consent was obtained.
Method details
requestConsent
public static void requestConsent(AdCallback<Integer> onComplete)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
onCompleteAdCallback<Integer>- 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.