I am trying to obtain consent with the User Messaging Platform (UMP). I have followed the official documentation, but I still have some questions.
When I try to test the consent flow using the
setConsentDebugSettings()
method, it does not work. I had to go into the AdMob console under Privacy & Messages and change the geography target for my GDPR dialog from Countries subject to GDPR (EEA and UK) to Everywhere. Only then was the consent dialog able to display.After the consent dialog has been displayed to the user and they have either consented or rejected, I am not sure where to initialize the AdMob SDK and load the ads.
Every time the app is launched, the consent process starts again and again. I am not sure if this is because I keep calling
consentInformation.reset()
in the code.Finally, I do not know what to do if
consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.UNKNOWN
is true. Should I initialize the SDK and load ads, or not? What about ifonConsentInfoUpdateFailure(FormError formError)
occurs?
I am all turned around. Please help me! Here is the code I have attempted so far:
I hope this helps! Let me know if you have any other questions.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
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()) {
if (consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.REQUIRED) {
loadForm();
consentInformation.reset();
}
else
if (consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.NOT_REQUIRED
||consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.OBTAINED) {
InnitializeAdmobSdk();
Load_Admob_ads();
consentInformation.reset();
}
else
if (consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.UNKNOWN) {
Toast.makeText(MainActivity.this, "UNKNOWN"+" "+consentInformation.getConsentStatus(), Toast.LENGTH_SHORT).show();
consentInformation.reset();
}
}else{
if (consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.NOT_REQUIRED
||consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.OBTAINED) {
InnitializeAdmobSdk();
Load_Admob_ads();
consentInformation.reset();
}
else
if (consentInformation.getConsentStatus()== ConsentInformation.ConsentStatus.UNKNOWN) {
Toast.makeText(MainActivity.this, "UNKNOWN"+" "+consentInformation.getConsentStatus(), Toast.LENGTH_SHORT).show();
}
consentInformation.reset();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
This is the loadform method
public void loadForm() {
// Loads a consent form. Must be called on the main thread.
UserMessagingPlatform.loadConsentForm(
this,
new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
@Override
public void onConsentFormLoadSuccess(ConsentForm consentForm) {
MainActivity.this.consentForm = consentForm;
if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
consentForm.show(
MainActivity.this,
new ConsentForm.OnConsentFormDismissedListener() {
@Override
public void onConsentFormDismissed(@Nullable FormError formError) {
if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
// App can start requesting ads.
}
// Handle dismissal by reloading form.
loadForm();
}
});
}
}
},
new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
@Override
public void onConsentFormLoadFailure(FormError formError) {
// Handle the error.
}
}
);
}