gpt4 book ai didi

java - tagForChildDirectedTreatment(boolean) 弃用

转载 作者:行者123 更新时间:2023-11-30 06:40:43 29 4
gpt4 key购买 nike

我正在尝试将库“com.google.android.gms:play-services-ads”从版本 17.2.0 更新到 18.1.1。我收到一条警告,提示方法 builder.tagForChildDirectedTreatment(true) 已被弃用。

在文档(https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest.Builder)中,据说应该改用 setTagForChildDirectedTreatment(int)。但是我找不到任何关于如何使用它的例子。文档 ( https://developers.google.com/admob/android/targeting) 未更新。他们仍然使用已弃用的 tagForChildDirectedTreatment(true)。有人可以帮我吗?

这是我的代码:

private void loadAds() {
MobileAds.initialize(this, getString(R.string.adMobAppId));
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.adMobUnitId));
Bundle extras = new Bundle();
extras.putBoolean("is_designed_for_families", true);
AdRequest.Builder builder = new AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras);
builder.tagForChildDirectedTreatment(true);
mInterstitialAd.loadAd(builder.build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {

if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}

}
});
}

最佳答案

因为我遇到了同样的问题,找不到任何答案,所以写下了,但我不知道对不对

这是我的代码

RequestConfiguration conf= new RequestConfiguration.Builder().setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE).build();

MobileAds.setRequestConfiguration(conf);
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);

关于java - tagForChildDirectedTreatment(boolean) 弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57275821/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com