代码之家  ›  专栏  ›  技术社区  ›  pequeñaluna

UMP SDK的ConsentFormDismissed方法应该放什么?

  •  0
  • pequeñaluna  · 技术社区  · 2 年前

    我遵循了官方的Android文档来实现UMP。

    这是我的代码:

    public class MainActivity extends AppCompatActivity {
      private ConsentInformation consentInformation;
      private ConsentForm consentForm;
    
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        consent();
       }
    
        public void consent() {
            ConsentRequestParameters params = new ConsentRequestParameters
                    .Builder()
                    .setTagForUnderAgeOfConsent(false)
                    .build();
    
            consentInformation = UserMessagingPlatform.getConsentInformation(this);
            consentInformation.requestConsentInfoUpdate(this,
                    params,
                    new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
                        @Override
                        public void onConsentInfoUpdateSuccess() {
                            // The consent information state was updated.
                            // You are now ready to check if a form is available.
                            if (consentInformation.isConsentFormAvailable()) {
                                loadForm();
                            }
                        }
                    },
                    new ConsentInformation.OnConsentInfoUpdateFailureListener() {
                        @Override
                        public void onConsentInfoUpdateFailure(FormError formError) {
                            // Handle the error.
                        }
                    });
    
        }
    
        public void loadForm() {
            // Loads a consent form. Must be called on the main thread.
            UserMessagingPlatform.loadConsentForm(
                    this,
                    new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
                        @Override
                        public void onConsentFormLoadSuccess(ConsentForm consentForm) {
                            MainActivity.this.consentForm = consentForm;
                            if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
                                consentForm.show(
                                        MainActivity.this,
                                        new ConsentForm.OnConsentFormDismissedListener() {
                                            @Override
                                            public void onConsentFormDismissed(FormError formError) {
                                                if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                                                    // App can start requesting ads.
                                                     //what should be here?
                                                }
    
                                                // Handle dismissal by reloading form.
                                                loadForm();
                                            }
                                        });
                            }
                        }
                    },
                    new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
                        @Override
                        public void onConsentFormLoadFailure(FormError formError) {
                            loadForm();
                        }
                    }
            );
        }
    

    好吧,如果我正确地实现了它,我的问题是,我应该在下面的if语句中放入什么:

     if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                                                    // App can start requesting ads.
                                                     //what should be here?
                                                }
    

    也许正在初始化移动广告?:

     MobileAds.initialize(this, initializationStatus -> {
    });
    

    我不知道什么是最好的选择。因为如果在用户接受或拒绝表单之前加载了广告,那么尝试在没有初始化移动广告的情况下加载广告将不是一个好的做法。我感谢所有可能的帮助:)

    0 回复  |  直到 2 年前
        1
  •  -1
  •   starball Martin Jorgensen    2 年前

    我强烈建议在用户同意后加载所有广告。 根据GDPR,收集个性化用户数据必须获得同意。AdMob和AdSense收集这些个人用户数据。 [在这里][1]你可以看到谷歌希望你做什么。 此外,当您想与第三方共享个人数据时,尤其是当您将这些信息发送到GDPR范围之外的国家时,您必须征得其同意。

    还有一个选项: 你放了一个 public static boolean consentGiven = false; 在您的应用程序中的某个位置。在if语句中,您将其设置为true(当然是在用户单击同意之后)。然后您可以随时检查变量 consentGiven 在你以任何方式收集个人信息之前。我知道这看起来像是一个很大的努力,但这是法律。

    推荐文章