MobileAds.initialize(Context, String) 已弃用
在它看起来像这样之前(通过):R.string.admob_application_id
MobileAds.initialize(this, getString(R.string.admob_application_id));
MobileAds
方法现在显示为:.initialize(Context context, String applicationCode)
此方法已弃用。请改用
initialize(Context, OnInitializationCompleteListener)。
内容如下:
初始化 Google Mobile Ads SDK。尽早调用此方法,以减少会话的第一个广告请求的延迟。如果未调用此方法,则第一个广告请求会自动初始化 Google 移动广告 SDK。
MobileAds.Settings也被弃用。
到目前为止,我尝试的是获取每个适配器的初始化状态
:
MobileAds.initialize(this, initializationStatus -> {
/* get the adapter status */
Map<String, AdapterStatus> map = initializationStatus.getAdapterStatusMap();
for (Map.Entry<String, AdapterStatus> entry : map.entrySet()) {
AdapterStatus adapterStatus = entry.getValue();
AdapterStatus.State state = adapterStatus.getInitializationState();
Log.d(LOG_TAG, "key = " + entry.getKey() + ", state = " + state.name() + ", desc = " + adapterStatus.getDescription());
}
});
在模拟器上,它说,但有一个相当令人困惑的消息:READY
.getDescription()
Google Mobile Ads SDK initialization functionality unavailable for this session.
Ad requests can be made at any time.
在具有互联网连接的物理设备上,它显示了另外四个适配器:
key = com.google.android.gms.ads.MobileAds, state = READY, desc =
key = com.google.ads.mediation.vungle.VungleMediationAdapter, state = NOT_READY, desc = Failed to create Adapter.
key = com.google.ads.mediation.applovin.AppLovinMediationAdapter, state = NOT_READY, desc = Failed to create Adapter.
key = com.google.ads.mediation.adcolony.AdColonyMediationAdapter, state = NOT_READY, desc = Failed to create Adapter.
key = com.google.ads.mediation.tapjoy.TapjoyMediationAdapter, state = NOT_READY, desc = Failed to create Adapter.
om.google.android.gms.ads.MobileAds
读取 ,另一个读取和(没有设置中介,但它可以加载测试广告)。READY
com.google.ads.mediation.*
NOT_READY
Failed to create Adapter
MobileAds.initialize(this);
也有效(可选)。OnInitializationCompleteListener
它似乎在没有 的情况下工作,因此我的实际问题是:R.string.admob_application_id
设置是否仍为必填项 - 或者现在只是广告单元 ID?大多数文档仍然使用已弃用的初始化方法(类似于上面显示的方法),因此这并不清楚。R.string.admob_publisher_id
R.string.admob_application_id