tagForChildDirectedTreatment(boolean) deprecated

Olga :

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();
            }

        }
    });
}
Afshin Izadi :

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);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=126011&siteId=1