I am trying to update library 'com.google.android.gms:play-services-ads' from version 17.2.0 to 18.1.1. I got a warning that the method builder.tagForChildDirectedTreatment(true) was deprecated.
In documentation (https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest.Builder) it is said that setTagForChildDirectedTreatment(int) should be used instead. But I could not find any examples of how to use it. Documentation (https://developers.google.com/admob/android/targeting) was not updated. They still use deprecated tagForChildDirectedTreatment(true). Can somebody help me with that?
Here is my code:
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();
            }
        }
    });
}
As I had the same problem and I couldn't find any answer I wrote it, but I don't know whether it's right or not
here is my code
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);
Here is my code :
MobileAds.initialize(this, id);
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
        .setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
        .build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With