Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tagForChildDirectedTreatment(boolean) deprecated

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

        }
    });
}
like image 429
Olga Avatar asked Jul 30 '19 16:07

Olga


2 Answers

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);
like image 192
Afshin Izadi Avatar answered Nov 10 '22 02:11

Afshin Izadi


Here is my code :

MobileAds.initialize(this, id);
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
        .setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
        .build();
like image 1
zTieuMyz Avatar answered Nov 10 '22 02:11

zTieuMyz