Should we first call MobileAds.setRequestConfiguration or MobileAds.initialize?

十年热恋 提交于 2020-05-11 05:32:07

问题


There isn't much documentation on this. I was wondering, should we first call

RequestConfiguration conf= new RequestConfiguration.Builder()
        .setMaxAdContentRating(
                MAX_AD_CONTENT_RATING_T)
        .build();

MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);

Or

MobileAds.initialize(context, APP_ID);
RequestConfiguration conf= new RequestConfiguration.Builder()
        .setMaxAdContentRating(
                MAX_AD_CONTENT_RATING_T)
        .build();

MobileAds.setRequestConfiguration(conf);

In https://developers.google.com/admob/android/quick-start

Although Google recommend calling MobileAds.initialize as early as possible

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.

They also mention "request-specific flags" need to be set before MobileAds.initialize.

Warning: Ads may be preloaded by the Mobile Ads SDK or mediation partner SDKs upon calling MobileAds.initialize(). If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment or tag_for_under_age_of_consent), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.

So, not super clear on which should be called first.


回答1:


According to Google Developer support, the following is the right way to do

https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/17oVu0sABjs

RequestConfiguration conf= new RequestConfiguration.Builder()
        .setMaxAdContentRating(
                MAX_AD_CONTENT_RATING_T)
        .build();

MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);



回答2:


according to the official documentation

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.

So , you should initialize MobileAds first ,look at the example here form the official documentation :

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}


来源:https://stackoverflow.com/questions/58084706/should-we-first-call-mobileads-setrequestconfiguration-or-mobileads-initialize

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!