From 21c95a792261c911b1500164b6fb41bede5a5f92 Mon Sep 17 00:00:00 2001 From: Justin Malandruccolo Date: Mon, 18 Nov 2024 07:17:19 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 697616850 --- .../GoogleMobileAdsConsentManager.java | 33 +++++++++++++------ .../GoogleMobileAdsConsentManager.kt | 29 ++++++++++++---- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java b/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java index b649efa61..eed7a71fc 100644 --- a/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java +++ b/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java @@ -84,21 +84,34 @@ public void gatherConsent( ConsentRequestParameters params = new ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build(); - // [START gather_consent] + // [START request_consent_info_update] // Requesting an update to consent information should be called on every app launch. consentInformation.requestConsentInfoUpdate( activity, params, - () -> - UserMessagingPlatform.loadAndShowConsentFormIfRequired( - activity, - formError -> { - // Consent has been gathered. - onConsentGatheringCompleteListener.consentGatheringComplete(formError); - }), - requestConsentError -> + () -> // Called when consent information is successfully updated. + // [START_EXCLUDE silent] + loadAndShowConsentFormIfRequired(activity, onConsentGatheringCompleteListener), + // [END_EXCLUDE] + requestConsentError -> // Called when there's an error updating consent information. + // [START_EXCLUDE silent] onConsentGatheringCompleteListener.consentGatheringComplete(requestConsentError)); - // [END gather_consent] + // [END_EXCLUDE] + // [END request_consent_info_update] + } + + private void loadAndShowConsentFormIfRequired( + Activity activity, OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { + // [START load_and_show_consent_form] + UserMessagingPlatform.loadAndShowConsentFormIfRequired( + activity, + formError -> { + // Consent gathering process is complete. + // [START_EXCLUDE silent] + onConsentGatheringCompleteListener.consentGatheringComplete(formError); + // [END_EXCLUDE] + }); + // [END load_and_show_consent_form] } /** Helper method to call the UMP SDK method to present the privacy options form. */ diff --git a/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt b/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt index 2cd6fc945..e50d7d264 100644 --- a/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt +++ b/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt @@ -69,22 +69,39 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) { val params = ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build() - // [START gather_consent] + // [START request_consent_info_update] // Requesting an update to consent information should be called on every app launch. consentInformation.requestConsentInfoUpdate( activity, params, { - UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError -> - // Consent has been gathered. - onConsentGatheringCompleteListener.consentGatheringComplete(formError) - } + // Called when consent information is successfully updated. + // [START_EXCLUDE silent] + loadAndShowConsentFormIfRequired(activity, onConsentGatheringCompleteListener) + // [END_EXCLUDE] }, { requestConsentError -> + // Called when there's an error updating consent information. + // [START_EXCLUDE silent] onConsentGatheringCompleteListener.consentGatheringComplete(requestConsentError) + // [END_EXCLUDE] }, ) - // [END gather_consent] + // [END request_consent_info_update] + } + + private fun loadAndShowConsentFormIfRequired( + activity: Activity, + onConsentGatheringCompleteListener: OnConsentGatheringCompleteListener, + ) { + // [START load_and_show_consent_form] + UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError -> + // Consent gathering process is complete. + // [START_EXCLUDE silent] + onConsentGatheringCompleteListener.consentGatheringComplete(formError) + // [END_EXCLUDE] + } + // [END load_and_show_consent_form] } /** Helper method to call the UMP SDK method to show the privacy options form. */