0

按照本指南https://developers.google.com/admob/ump/android/quick-start我尝试将所有内容添加到我的应用程序中。

我做了什么:

  • 将资金选择链接到 admob
  • 将 ump 添加到 build.gradle
  • 将应用 ID 添加到 android manifest
  • 在 admob 中为应用程序设置一个对话框并为应用程序激活它

然后我将此代码添加到我的应用程序中

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();
                        }
                        else {

                        Context context = getApplicationContext();

                        CharSequence toastText = "No Form Available";

                        int duration = Toast.LENGTH_LONG;

                        Toast toast = Toast.makeText(context, toastText, duration);
                        toast.show();
                        }

                        
                    }

                },
                new ConsentInformation.OnConsentInfoUpdateFailureListener() {
                    @Override
                    public void onConsentInfoUpdateFailure(FormError formError) {
                        // Handle the error.
                        
                        Context context = getApplicationContext();

                        CharSequence toastText = "Error";

                        int duration = Toast.LENGTH_LONG;

                        Toast toast = Toast.makeText(context, toastText, duration);
                        toast.show();

                    }
                });

public void loadForm() {
        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(@Nullable FormError formError) {
                                            // Handle dismissal by reloading form.
                                            loadForm();
                                        }
                                    });

                        }
                    }
                },
                new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
                    @Override
                    public void onConsentFormLoadFailure(FormError formError) {
                        // Handle the error
                    }
                }
        );
    }

但是,我总是在 onConsentInfoUpdateFailure(FormError formError) 独立于我的手机或虚拟设备上的测试(我在欧洲顺便说一句)中获得吐司“错误”。

我错过了什么吗?

谢谢, 塞尔德里

4

1 回答 1

-1

我遇到了同样的问题,我只是通过正确配置我的 adMob 帐户来解决它。

于 2021-10-01T18:54:08.757 回答