gpt4 book ai didi

android - 什么应该替换已弃用的 Facebook adView setAdListener 以获取回调?

转载 作者:行者123 更新时间:2023-12-02 06:46:41 25 4
gpt4 key购买 nike

从 v5.6.0 开始,不推荐使用 adView.setAdListener。我们现在如何接收 onAdLoaded 和 onError 回调?

最佳答案

解决方案:从 5.6 开始,您应该使用 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)

查找更多信息 here .

关于android - 什么应该替换已弃用的 Facebook adView setAdListener 以获取回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59560897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com