我正在我的应用程序中实现UMP-sdk,它显然是有效的,但我想确保这是实现它的正确方式:
这是我的代码:
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();
}
}
);
}
我有三个问题:
1-我的实施看起来不错吗?
2-当ConsentStatus为ConsentStatus时,这是MobileAds.initialize()的好方法吗。像我一样获得?
3-我什么都不用做了,对吧?我的意思是,当用户接受或拒绝表单时,谷歌会自动个性化广告,而无需我管理,对吧?我的意思是,我不必对个性化部分进行编码,对吧?