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: 686987300
  • Loading branch information
Interactive Media Ads Developer Relations authored and IMA Developer Relations committed Oct 17, 2024
1 parent 0f84edf commit 4f596ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 ->
Expand All @@ -118,6 +124,7 @@ protected void onCreate(Bundle savedInstanceState) {
}));
}

// [START request_ads]
private void initializeImaSdk() {
sdkFactory = ImaSdkFactory.getInstance();

Expand All @@ -128,6 +135,8 @@ private void initializeImaSdk() {
setUpPlayButton();
}

// [END request_ads]

private void createAdsLoader() {
// Create an AdsLoader.
ImaSdkSettings settings = sdkFactory.createImaSdkSettings();
Expand Down

0 comments on commit 4f596ff

Please sign in to comment.