【问题标题】:GDPR Consent Dialog won't showGDPR 同意对话框不会显示
【发布时间】:2018-05-27 03:28:29
【问题描述】:

我正在尝试通过使用 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();
    }

【问题讨论】:

    标签: java android admob cookieconsent


    【解决方案1】:

    我遇到了完全相同的问题。问题是由于 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();
    

    【讨论】:

    • 天哪!你是对的。似乎有一个错误。不过我延迟了它的实现。
    【解决方案2】:

    确保添加此行以在非欧盟地区进行测试。

    ConsentInformation.getInstance(context).
        setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
    

    【讨论】:

      【解决方案3】:

      正如Alexandru Topală 提到的,您不能在load() 之后立即调用show()

      文档记录很差...

      我用 kotlin 实现了,late init:

      lateinit var form: ConsentForm
      form = ConsentForm.Builder(this@HomeActivity, privacyUrl)
              .withListener(object : ConsentFormListener() {
                  override fun onConsentFormLoaded() {
                      form.show()
                  }
      
                  override fun onConsentFormOpened() {}
      
                  override fun onConsentFormClosed(consentStatus: ConsentStatus, userPrefersAdFree: Boolean) {
                      viewModel.consentUpdate(consentStatus)
                      if (userPrefersAdFree) {
                          PurchaseActivity.startActivity(this@HomeActivity)
                      }
                  }
      
                  override fun onConsentFormError(errorDescription: String) {
                      Timber.e(RuntimeException(errorDescription), "Failed to open consent form.")
                  }
              })
              .withPersonalizedAdsOption()
              .withNonPersonalizedAdsOption()
              .withAdFreeOption()
              .build()
      form.load()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-10
        • 1970-01-01
        • 2016-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多