Mirawo
unread,Jun 5, 2023, 3:46:20 PM6/5/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Mobile Ads SDK Developers
I am implementing UMP sdk in my app and it is working apparently, but I want to ensure that this is the correct way of implementing it:
Here is my code:
public class MainActivity extends AppCompatActivity {
private ConsentInformation consentInformation;
private ConsentForm consentForm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
consent();
}
public void consent() {
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()) {
loadForm();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
}
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(FormError formError) {
if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
MobileAds.initialize(this, initializationStatus -> {
});
}
// Handle dismissal by reloading form.
loadForm();
}
});
}
}
},
new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
@Override
public void onConsentFormLoadFailure(FormError formError) {
loadForm();
}
}
);
}
I have three questions:
1- Is my implementation looking good?
2- Is it a good way to MobileAds.initialize() when ConsentStatus is ConsentStatus.OBTAINED as I have done?
3- I don't have to do anything more, right? I mean when the user accepts or declines the Form, google will automatically personalize ads without my need of managing that, right? I mean, I don't have to code the personalization part, right?