Search code examples
androidadmobbanner-ads

After updating Google Ads SDK onAdFailedToLoad is deprecated, How to resolve?


After updating Google Ads SDK to 19.3.0 gives a deprecated warning message for onAdFailedToLoad(). How can I resolve this?

My code:

public void BannerAdMob() {
        final AdView adView = findViewById(R.id.adsView);
        adView.loadAd(new AdRequest.Builder().build());
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                
            }

            @Override
            public void onAdFailedToLoad(int error) { // this method is deprecated 
                
            }
        });
    }

Solution

  • They added a new method you should override instead of that one:

    public void onAdFailedToLoad (LoadAdError adError)

    You can get a bunch of information from the adError object, calling getCode() on it will give you the code that the old method had.