-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UMP SDK integration to Ad Manager Banner Java & Kotlin samples
PiperOrigin-RevId: 557119541
- Loading branch information
1 parent
861b463
commit 6c32363
Showing
15 changed files
with
397 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.google.android.gms.example.bannerexample; | ||
|
||
import android.app.Activity; | ||
import androidx.annotation.NonNull; | ||
import com.google.android.ump.ConsentDebugSettings; | ||
import com.google.android.ump.ConsentForm.OnConsentFormDismissedListener; | ||
import com.google.android.ump.ConsentInformation; | ||
import com.google.android.ump.ConsentInformation.PrivacyOptionsRequirementStatus; | ||
import com.google.android.ump.ConsentRequestParameters; | ||
import com.google.android.ump.FormError; | ||
import com.google.android.ump.UserMessagingPlatform; | ||
|
||
/** | ||
* The Google Mobile Ads SDK provides the User Messaging Platform (Google's | ||
* IAB Certified consent management platform) as one solution to capture | ||
* consent for users in GDPR impacted countries. This is an example and | ||
* you can choose another consent management platform to capture consent. | ||
*/ | ||
public class GoogleMobileAdsConsentManager { | ||
private final Activity activity; | ||
private final ConsentInformation consentInformation; | ||
|
||
/** Interface definition for a callback to be invoked when consent gathering is complete. */ | ||
public interface OnConsentGatheringCompleteListener { | ||
void consentGatheringComplete(FormError error); | ||
} | ||
|
||
/** Constructor */ | ||
public GoogleMobileAdsConsentManager(@NonNull Activity activity) { | ||
this.activity = activity; | ||
this.consentInformation = UserMessagingPlatform.getConsentInformation(activity); | ||
} | ||
|
||
/** Helper variable to determine if the app can request ads. */ | ||
public boolean canRequestAds() { | ||
return consentInformation.canRequestAds(); | ||
} | ||
|
||
/** Helper variable to determine if the privacy options form is required. */ | ||
public boolean isPrivacyOptionsRequired() { | ||
return consentInformation.getPrivacyOptionsRequirementStatus() | ||
== PrivacyOptionsRequirementStatus.REQUIRED; | ||
} | ||
|
||
/** Helper method to call the UMP SDK methods to request consent information and load/present a | ||
* consent form if necessary. */ | ||
public void gatherConsent( | ||
OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { | ||
// For testing purposes, you can force a DebugGeography of EEA or NOT_EEA. | ||
ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity) | ||
// .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) | ||
// Check your logcat output for the hashed device ID e.g. | ||
// "Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("ABCDEF012345")" to use | ||
// the debug functionality. | ||
.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID") | ||
.build(); | ||
|
||
ConsentRequestParameters params = new ConsentRequestParameters.Builder() | ||
.setConsentDebugSettings(debugSettings) | ||
.build(); | ||
|
||
// 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 -> | ||
onConsentGatheringCompleteListener.consentGatheringComplete(requestConsentError) | ||
); | ||
} | ||
|
||
/** Helper method to call the UMP SDK method to present the privacy options form. */ | ||
public void showPrivacyOptionsForm( | ||
Activity activity, | ||
OnConsentFormDismissedListener onConsentFormDismissedListener) { | ||
UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
java/admanager/BannerExample/app/src/main/res/menu/action_menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
android:id="@+id/action_more" | ||
android:icon="@android:drawable/ic_menu_preferences" | ||
android:title="@string/more_menu" | ||
app:showAsAction="always" | ||
android:visible="false"/> | ||
</menu> |
6 changes: 6 additions & 0 deletions
6
java/admanager/BannerExample/app/src/main/res/menu/popup_menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:id="@+id/privacy_settings" | ||
android:title="@string/privacy_settings" /> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.