我按照Android文档上的指南进行操作,但由于某些原因,启动我的应用程序时未显示任何内容。
我什至尝试记录侦听器,但logcat中没有任何显示。

我也将admob设置中的广告技术更改为广告技术提供商的自定义设置,但仍然无法使用。

我的密码

 ConsentInformation consentInformation = ConsentInformation.getInstance(getApplicationContext());
        ConsentInformation.getInstance(getApplicationContext()).addTestDevice("6AE7D8950FE9E464D988F340C0D625B0");
        ConsentInformation.getInstance(getApplicationContext()).
                setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
        String[] publisherIds = {"pub-4427787827947251"};
        consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
            @Override
            public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                // User's consent status successfully updated.
                Log.d(TAG,"onConsentInfoUpdated");
            }

            @Override
            public void onFailedToUpdateConsentInfo(String errorDescription) {
                // User's consent status failed to update.
                Log.d(TAG,"onFailedToUpdateConsentInfo");
            }
        });

        URL privacyUrl = null;
        try {
            // TODO: Replace with your app's privacy policy URL.
            privacyUrl = new URL("https://mp3icious.github.io/mp3icious.privacy-policy/");
        } catch (MalformedURLException e) {
            e.printStackTrace();
            // Handle error.
        }
        form = new ConsentForm.Builder(this, privacyUrl)
                .withListener(new ConsentFormListener() {
                    @Override
                    public void onConsentFormLoaded() {
                        // Consent form loaded successfully.
                        Log.d(TAG,"form loaded!");
                        form.show();
                    }

                    @Override
                    public void onConsentFormOpened() {
                        // Consent form was displayed.
                    }

                    @Override
                    public void onConsentFormClosed(
                            ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                        // Consent form was closed.
                    }

                    @Override
                    public void onConsentFormError(String errorDescription) {
                        // Consent form error.
                        Log.d(TAG,"form error!");
                    }
                })
                .withPersonalizedAdsOption()
                .withNonPersonalizedAdsOption()
                .withAdFreeOption()
                .build();

        form.load();


摇篮

dependencies {
        classpath 'com.google.gms:google-services:4.3.2'
   }



implementation 'com.google.android.ads.consent:consent-library:1.0.7'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'com.google.android.gms:play-services-ads:18.2.0'


编辑

我在android x之前的项目上尝试过,现在它调用了监听器onFailedToUpdateConsentInfo

随着以下错误消息:

onFailedToUpdateConsentInfoCould not parse Event FE preflight response.


搜索了一下,发现这可能是因为无效的发布ID,但我确定我使用的是正确的发布ID。

最佳答案

1)我认为您忘记了检查isRequestLocationInEeaOrUnknown()方法。
如果用户已经同意,它将返回true。在这种情况下,您无需再次询问。我认为您已经同意同意。

包装您的代码

if(ConsentInformation.getInstance(context).isRequestLocationInEeaOrUnknown()){
     //setup admob
}else{
     //Ask for consent
}


2)您必须调用form.show();将表单提交给用户,然后选中Google Doc

关于java - GDPR同意对话框未显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58334452/

10-11 08:55