Java GDPR同意对话获胜';不显示
我正试图通过使用谷歌新的同意SDK将GDPR同意对话框添加到我的应用程序中(我不住在欧盟),但我不能,这是我运行时的代码对话框不会打开,我尝试使用VPN,但仍然没有出现相同的对话框Java GDPR同意对话获胜';不显示,java,android,admob,cookieconsent,Java,Android,Admob,Cookieconsent,我正试图通过使用谷歌新的同意SDK将GDPR同意对话框添加到我的应用程序中(我不住在欧盟),但我不能,这是我运行时的代码对话框不会打开,我尝试使用VPN,但仍然没有出现相同的对话框 /*GDRP*/ ConsentInformation consentInformation = ConsentInformation.getInstance(this); String[] publisherIds = {"pub-xxxxx...."}; conse
/*GDRP*/
ConsentInformation consentInformation = ConsentInformation.getInstance(this);
String[] publisherIds = {"pub-xxxxx...."};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
}
});
URL privacyUrl = null;
try {
// TODO: Replace with your app's privacy policy URL.
privacyUrl = new URL("URL");
} catch (MalformedURLException e) {
e.printStackTrace();
// Handle error.
}
form = new ConsentForm.Builder(this, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded(){
showForm();
}
@Override
public void onConsentFormOpened() {
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
}
@Override
public void onConsentFormError(String errorDescription) {
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
form.load();
private void showForm() {
form.show();
}
我也有同样的问题。问题是,由于SDK中的错误,当您试图显示表单时,表单没有完全加载 这应该解决这个问题:
// declare your form up
ConsentForm form;
// declare this function that will show the form
protected void showConsentForm(){
form.show();
}
// on the onCreate
form = new ConsentForm.Builder(context, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.d("SplashScreen", "Consent form Loaded ");
showConsentForm();
}
@Override
public void onConsentFormOpened() {
// Consent form was displayed.
Log.d("SplashScreen", "Consent form opened ");
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
Log.d("SplashScreen", "Consent form Closed ");
}
@Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.d("SplashScreen", "Consent form error " + errorDescription);
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.build();
// load the form so we can call .show on it after
form.load();
确保将此行添加到非欧盟地区的测试中
ConsentInformation.getInstance(context).
setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
如前所述,您不能在load()
之后立即调用show()
记录得很差
我用kotlin实现了它,并且late init
:
lateinit变量表单:同意表单
form=form.Builder(this@HomeActivity,privacyUrl)
.withListener(对象:ApprovementFormListener(){
覆盖onConsentFormLoaded(){
表格.show()
}
重写OnConsentForMopend(){}
覆盖fun onConsentFormClosed(同意状态:同意状态,用户首选自由:布尔值){
viewModel.ApprovementUpdate(ApprovementStatus)
if(userPrefersAdFree){
PurchaseActivity.startActivity(this@HomeActivity)
}
}
重写onConsentFormError(错误描述:字符串){
Timber.e(RuntimeException(errorDescription),“无法打开同意书。”)
}
})
.withPersonalizedAdsOption()
.使用非个性化数据选项()
.withAdFreeOption()
.build()
form.load()
神圣的s4it!你是对的。好像有个虫子。但是我延迟了它的实现。