Skip to content

Commit

Permalink
Added requestConsent in Android project
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Jul 19, 2023
1 parent 5f66d7b commit d4151c8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,6 @@ public void initialize(){
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});

ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity)
.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
.build();

// Set tag for under age of consent. false means users are not under
// age.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
//.setConsentDebugSettings(debugSettings)
.setTagForUnderAgeOfConsent(false)
.build();

consentInformation = UserMessagingPlatform.getConsentInformation(activity);
//consentInformation.reset();
consentInformation.requestConsentInfoUpdate(
activity,
params,
new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
@Override
public void onConsentInfoUpdateSuccess() {
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.isConsentFormAvailable()) {
//loadForm();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
}
});
}
Expand All @@ -98,11 +63,6 @@ public void tagForChildDirectedTreatment(boolean enable){
.setTagForChildDirectedTreatment(tagValue)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);

ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
}
});
}
Expand All @@ -126,7 +86,52 @@ public void tagForUnderAgeOfConsent(boolean enable){
});
}

public void loadForm() {
public void requestConsent(){
boolean tagUnderAgeCOnsent = false;
if (MobileAds.getRequestConfiguration().getTagForChildDirectedTreatment() == RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE){
tagUnderAgeCOnsent = true;
}
if (MobileAds.getRequestConfiguration().getTagForUnderAgeOfConsent() == RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE){
tagUnderAgeCOnsent = true;
}

ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(activity)
.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
.build();

// Set tag for under age of consent. false means users are not under
// age.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
//.setConsentDebugSettings(debugSettings)
.setTagForUnderAgeOfConsent(tagUnderAgeCOnsent)
.build();

consentInformation = UserMessagingPlatform.getConsentInformation(activity);
//consentInformation.reset();
consentInformation.requestConsentInfoUpdate(
activity,
params,
new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
@Override
public void onConsentInfoUpdateSuccess() {
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.isConsentFormAvailable()) {
loadForm();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
}

private void loadForm() {
// Loads a consent form. Must be called on the main thread.
UserMessagingPlatform.loadConsentForm(
activity,
Expand Down
2 changes: 1 addition & 1 deletion workspaces/androidstudio/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ android {
}

dependencies {
implementation "com.google.android.gms:play-services-ads:22.0.0"
implementation "com.google.android.gms:play-services-ads:22.2.0"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.games:games-activity:2.0.2"
implementation "androidx.games:games-frame-pacing:2.0.0"
Expand Down

0 comments on commit d4151c8

Please sign in to comment.