diff --git a/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/ConsentManager.java b/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/ConsentManager.java index ed7e52c..8e2b412 100644 --- a/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/ConsentManager.java +++ b/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/ConsentManager.java @@ -36,12 +36,15 @@ public boolean canRequestAds() { return consentInformation.canRequestAds(); } + // [START is_privacy_options_required] /** Helper function to determine if GDPR consent messages are required. */ public boolean areGDPRConsentMessagesRequired() { return consentInformation.getPrivacyOptionsRequirementStatus() == PrivacyOptionsRequirementStatus.REQUIRED; } + // [END is_privacy_options_required] + /** Load remote updates of consent messages and gather previously cached user consent. */ public void gatherConsent(OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. @@ -65,6 +68,7 @@ public void gatherConsent(OnConsentGatheringCompleteListener onConsentGatheringC .setConsentDebugSettings(debugSettings) .build(); + // [START gather_consent] // Requesting an update to consent information should be called on every app launch. consentInformation.requestConsentInfoUpdate( activity, @@ -73,11 +77,14 @@ public void gatherConsent(OnConsentGatheringCompleteListener onConsentGatheringC UserMessagingPlatform.loadAndShowConsentFormIfRequired( activity, onConsentGatheringCompleteListener::consentGatheringComplete), onConsentGatheringCompleteListener::consentGatheringComplete); + // [END gather_consent] } /** Shows a form to app users for collecting their consent. */ public void showPrivacyOptionsForm( Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) { + // [START present_privacy_options_form] UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); + // [END present_privacy_options_form] } } diff --git a/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/MyActivity.java b/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/MyActivity.java index 3164df3..ff8511e 100644 --- a/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/MyActivity.java +++ b/umpexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/umpimaapp/MyActivity.java @@ -83,6 +83,7 @@ protected void onCreate(Bundle savedInstanceState) { Button privacyButton = findViewById(R.id.privacyButton); consentManager = new ConsentManager(this); + // [START can_request_ads] consentManager.gatherConsent( consentError -> { if (consentError != null) { @@ -99,13 +100,18 @@ protected void onCreate(Bundle savedInstanceState) { } else { Log.i(LOGTAG, "Consent not available to request ads"); } + // [START_EXCLUDE] + // [START add_privacy_options] // Check ConsentInformation.getPrivacyOptionsRequirementStatus() to see the button should // be shown or hidden. if (consentManager.areGDPRConsentMessagesRequired()) { privacyButton.setVisibility(View.VISIBLE); } + // [END add_privacy_options] + // [END_EXCLUDE] }); + // [END can_request_ads] privacyButton.setOnClickListener( button -> @@ -118,6 +124,7 @@ protected void onCreate(Bundle savedInstanceState) { })); } + // [START request_ads] private void initializeImaSdk() { sdkFactory = ImaSdkFactory.getInstance(); @@ -128,6 +135,8 @@ private void initializeImaSdk() { setUpPlayButton(); } + // [END request_ads] + private void createAdsLoader() { // Create an AdsLoader. ImaSdkSettings settings = sdkFactory.createImaSdkSettings();