java - GDPR 同意对话框不会显示
问题描述
我正在尝试通过使用 Google 提供的新 Consent SDK 将GDPR 同意 dialog
添加到我的应用程序中,(我不住在欧盟)但是当我运行它时,我不能这是我的代码,对话框不会打开,我尝试使用 VPN 但仍然没有出现相同的对话框
/*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();
推荐阅读
- javascript - 如何访问从 MVC 视图中的 ajax 调用调用的控制器返回的数据
- android - Jetpack Compose 中的高度垫片 (HeightSpacer)
- angular - 在 Ionic 4 中使用查询参数
- python - (Maya Python) 如何通过 GUI 函数运行单选选项按钮?
- python - 如何计算 python pandas 数据帧的第一条和最后一条记录之间的时间差异
- azure - Azure 管道“WinRMCustomScriptExtension”基础连接在非公共 VM 中关闭
- python - 在没有附加模块的 lambda 函数中使用反 cos
- vim - 如何在 Vim 中始终将文本保存在缓冲区中>
- excel - 将选项卡组合在一起时设置条件的问题
- css - :not css 选择器未按预期工作