我正在尝试设置GDPR的同意书,但表单给出了错误:请求不在EEA或未知。我如何欺骗我在EEA的位置,以便我可以测试表格?我假设ConsentInformation类必须以某种方式获得我的GPS坐标,即使我已经尝试在手机和模拟器上运行它(两者的结果相同)。这是我的代码(与文档相同):
public class MainActivity extends AppCompatActivity {
ConsentForm form;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Timber.d(" *** Main Activity *** ");
getConsent();
showConsentForm();
}
public void getConsent() {
Timber.d ("Attempting to get consent");
ConsentInformation consentInformation = ConsentInformation.getInstance(this);
String[] publisherIds = {"pub-2153652996366584"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
}
});
}
public void showConsentForm() {
Timber.d ("Building consent form");
URL privacyUrl = null;
try {
privacyUrl = new URL("https://www.your.com/privacyurl");
} catch (MalformedURLException e) {
Timber.e(e.getMessage());
}
form = new ConsentForm.Builder(this, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
Timber.d("Consent form loaded successfully.");
}
@Override
public void onConsentFormOpened() {
Timber.d("Consent form was displayed.");
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
Timber.d("Consent form was closed.");
}
@Override
public void onConsentFormError(String errorDescription) {
Timber.d("Consent form error:" + errorDescription);
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
}
public void onConsentLoadClick(View view) {
Timber.d("Loading the Consent Form");
form.load();
}
public void onConsentShowClick(View view) {
Timber.d("Showing the consent form");
form.show();
}
答案 0 :(得分:5)
谷歌在https://developers.google.com/admob/android/eu-consent下根据"测试"他们有关于如何测试欧洲经济区以外用户的说明。
希望这有帮助!
// Geography appears as in EEA for test devices.
ConsentInformation.getInstance(context).
consentInformation.addTestDevice("XXXXXXXXXXXXXXXXXXXXX");
consentInformation.setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
编辑:您还必须将您的设备添加为测试设备才能使其正常工作。初始化同意库后,您的设备的测试ID将显示在Logcat中。
答案 1 :(得分:1)