Skip to content

Commit

Permalink
Add includecode comments for UMP SDK integration
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 685819469
  • Loading branch information
Justin Malandruccolo authored and copybara-github committed Oct 14, 2024
1 parent 6ac1e9a commit 338d38a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ public boolean canRequestAds() {
return consentInformation.canRequestAds();
}

// [START is_privacy_options_required]
/** Helper variable to determine if the privacy options form is required. */
public boolean isPrivacyOptionsRequired() {
return consentInformation.getPrivacyOptionsRequirementStatus()
== PrivacyOptionsRequirementStatus.REQUIRED;
}

// [END is_privacy_options_required]

/**
* Helper method to call the UMP SDK methods to request consent information and load/present a
* consent form if necessary.
Expand All @@ -81,6 +84,7 @@ public void gatherConsent(
ConsentRequestParameters params =
new ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build();

// [START gather_consent]
// Requesting an update to consent information should be called on every app launch.
consentInformation.requestConsentInfoUpdate(
activity,
Expand All @@ -94,11 +98,14 @@ public void gatherConsent(
}),
requestConsentError ->
onConsentGatheringCompleteListener.consentGatheringComplete(requestConsentError));
// [END gather_consent]
}

/** Helper method to call the UMP SDK method to present the privacy options form. */
public void showPrivacyOptionsForm(
Activity activity, OnConsentFormDismissedListener onConsentFormDismissedListener) {
// [START present_privacy_options_form]
UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener);
// [END present_privacy_options_form]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ protected void onCreate(Bundle savedInstanceState) {
initializeMobileAdsSdk();
}

// [START add_privacy_options]
if (googleMobileAdsConsentManager.isPrivacyOptionsRequired()) {
// Regenerate the options menu to include a privacy setting.
invalidateOptionsMenu();
}
// [END add_privacy_options]
});

// This sample attempts to load ads using consent obtained in the previous session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) {
val canRequestAds: Boolean
get() = consentInformation.canRequestAds()

// [START is_privacy_options_required]
/** Helper variable to determine if the privacy options form is required. */
val isPrivacyOptionsRequired: Boolean
get() =
consentInformation.privacyOptionsRequirementStatus ==
ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED

// [END is_privacy_options_required]

/**
* Helper method to call the UMP SDK methods to request consent information and load/show a
* consent form if necessary.
Expand All @@ -66,6 +69,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) {

val params = ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build()

// [START gather_consent]
// Requesting an update to consent information should be called on every app launch.
consentInformation.requestConsentInfoUpdate(
activity,
Expand All @@ -80,6 +84,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) {
onConsentGatheringCompleteListener.consentGatheringComplete(requestConsentError)
},
)
// [END gather_consent]
}

/** Helper method to call the UMP SDK method to show the privacy options form. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ class MainActivity : AppCompatActivity() {
initializeMobileAdsSdk()
}

// [START add_privacy_options]
if (googleMobileAdsConsentManager.isPrivacyOptionsRequired) {
// Regenerate the options menu to include a privacy setting.
invalidateOptionsMenu()
}
// [END add_privacy_options]
}

// This sample attempts to load ads using consent obtained in the previous session.
Expand Down

0 comments on commit 338d38a

Please sign in to comment.