As of v5.6.0 the adView.setAdListener is deprecated. How can we receive onAdLoaded and onError callbacks now?
Solution: Since 5.6, you should use loadAd(AdView.AdViewLoadConfig loadAdConfig)
public void loadAd(AdView.AdViewLoadConfig loadAdConfig)
Loads an ad.
This method always returns immediately. The ad is loaded asynchronously. The control's ad listener will be called when loading finishes or fails.
Java
AdView adView = new AdView(this, "placementId", new AdSize(width, height));
AdListener adListener = new AdListener() {
@Override
public void onError(Ad ad, AdError adError) {
}
@Override
public void onAdLoaded(Ad ad) {
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onLoggingImpression(Ad ad) {
}
};
AdView.AdViewLoadConfig loadAdConfig = adView.buildLoadAdConfig()
.withAdListener(adListener)
.build();
adView.loadAd(loadAdConfig);
Kotlin
val adView = AdView(this, "placementId", AdSize(width, height))
val adListener = object : AdListener {
override fun onError(ad: Ad, adError: AdError) {
}
override fun onAdLoaded(ad: Ad) {
}
override fun onAdClicked(ad: Ad) {
}
override fun onLoggingImpression(ad: Ad) {
}
}
val loadAdConfig = adView.buildLoadAdConfig()
.withAdListener(adListener)
.build()
adView.loadAd(loadAdConfig)
Find more information here.