未显示Admob美国同意书表格

时间:2018-10-04 10:05:03

标签: android admob

今天,我正在我的应用程序中实施EU用户同意书,并且我遵循了Admob实施文件,但是Assets文件夹中的同意书不会显示,并且logcat说:“意外标识符”,来源:file:/// android_asset /consentform.html

这里有人曾经见过这个问题吗?以及如何解决?

广告技术提供商:我选择了少于12个提供商的“广告技术提供商的自定义集合”。

Logcat:

2018-10-04 16:44:35.570 31459-31459/kids.math.mathforkids I/ConsentInformation: This request is sent from a test device.
2018-10-04 16:44:39.067 31459-31459/kids.math.mathforkids I/chromium: [INFO:CONSOLE(717)] "Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/consentform.html (717)
2018-10-04 16:44:39.304 31459-31459/kids.math.mathforkids I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: setUpConsentDialog is not defined", source: file:///android_asset/consentform.html (1)

代码:

public class MainActivity extends AppCompatActivity {
private String TAG = this.getClass().getSimpleName();
private ConsentForm form;
private InterstitialAd mInterstitialAd;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    hideSystemUI();
    setContentView(R.layout.main_activity);
    MobileAds.initialize(this, "xxxx");

    checkForConsent();
}

//Admob Consent
private void checkForConsent() {

    ConsentInformation consentInformation = ConsentInformation.getInstance(this);
    //Test
    ConsentInformation.getInstance(this).addTestDevice("8E415EExxxxxxB8FADF");
    ConsentInformation.getInstance(this).setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
    //End Test

    String[] publisherIds = {"pub-2506xxxxx2"};

    consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
        @Override
        public void onConsentInfoUpdated(ConsentStatus consentStatus) {
            // User's consent status successfully updated.
            switch (consentStatus) {
                case PERSONALIZED:
                    Log.d(TAG, "Showing Personalized ads");
                    showPersonalizedAds();
                    break;
                case NON_PERSONALIZED:
                    Log.d(TAG, "Showing Non-Personalized ads");
                    showNonPersonalizedAds();
                    break;
                case UNKNOWN:
                    Log.d(TAG, "Requesting Consent");
                    if (ConsentInformation.getInstance(getBaseContext()).isRequestLocationInEeaOrUnknown()) {
                        requestConsent();
                    } else {
                        showPersonalizedAds();
                    }
                    break;
                default:
                    break;
            }
        }

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

private void requestConsent() {
    URL privacyUrl = null;
    try {
        privacyUrl = new URL("http://www.xxxxx.info/privacy.html");
    } 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, "Requesting Consent: onConsentFormLoaded");
                    showForm();
                }

                @Override
                public void onConsentFormOpened() {
                    // Consent form was displayed.
                    Log.d(TAG, "Requesting Consent: onConsentFormOpened");
                }

                @Override
                public void onConsentFormClosed(ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                    Log.d(TAG, "Requesting Consent: onConsentFormClosed");
                    if (userPrefersAdFree) {
                        // Buy or Subscribe
                        Log.d(TAG, "Requesting Consent: User prefers AdFree");
                    } else {
                        Log.d(TAG, "Requesting Consent: Requesting consent again");
                        switch (consentStatus) {
                            case PERSONALIZED:
                                showPersonalizedAds(); break;
                            case NON_PERSONALIZED:
                                showNonPersonalizedAds(); break;
                            case UNKNOWN:
                                showNonPersonalizedAds(); break;
                        }
                    }
                    // Consent form was closed.
                }

                @Override
                public void onConsentFormError(String errorDescription) {
                    Log.d(TAG, "Requesting Consent: onConsentFormError. Error - " + errorDescription);
                    // Consent form error.
                }
            })
            .withPersonalizedAdsOption()
            .withNonPersonalizedAdsOption()
            .withAdFreeOption()
            .build();
    form.load();
}

    ConsentInformation.getInstance(this).setConsentStatus(ConsentStatus.PERSONALIZED);
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-2cxxxxxx80560");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("8E415Exxxx07B8FADF").build());
    mInterstitialAd.setAdListener(new AdListener(){
        @Override
        public void onAdClosed() {
           mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("8E415EE0DBB1F96296E83A1A07B8FADF").build());
        }
    });
}

private void showNonPersonalizedAds() {
    ConsentInformation.getInstance(this).setConsentStatus(ConsentStatus.NON_PERSONALIZED);
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-25xxxx560");
    mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, getNonPersonalizedAdsBundle()).addTestDevice("8E415Easdfasdf07B8FADF").build());
    mInterstitialAd.setAdListener(new AdListener(){
        @Override
        public void onAdClosed() {
            mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, getNonPersonalizedAdsBundle()).addTestDevice("8E415EE0DBB1F96296E83A1A07B8FADF").build());
        }
    });
}
public Bundle getNonPersonalizedAdsBundle() {
    Bundle extras = new Bundle();
    extras.putString("npa", "1");
    return extras;
}

private void showForm() {
    if (form == null) {
        Log.d(TAG, "Consent form is null");
    }
    if (form != null) {
        Log.d(TAG, "Showing consent form");
        form.show();
    } else {
        Log.d(TAG, "Not Showing consent form");
    }
}
}

0 个答案:

没有答案