gpt4 book ai didi

java - 将 InterstitialAd 与 InterstitialAdListener 结合使用。获取错误消息

转载 作者:行者123 更新时间:2023-12-02 06:22:32 24 4
gpt4 key购买 nike

我在使用 InterstitialAdListener 时收到此错误

 Anonymous class derived from InterstitialAdListener' must either be declared > abstract or implement abstract method 'onInterstitialDismissed(Ad) in 
'InterstitialAdListener'

InterstitialAdListener 带有红色下划线。

我尝试将其缩小为com.facebook.ads.AdListener,但对我不起作用此外,我升级了SDK以查看是否可以解决该问题,但运气不佳。

我该如何解决这个问题?


private void initInterstitialAdPrepare() {
interstitialAd = new InterstitialAd(this, "xxxxxxxx_xxxxxxxxx");
interstitialAd.setAdListener(new InterstitialAdListener() {

@Override
public void onInterstitialDisplayed(Ad ad) {
// Interstitial ad displayed callback
Log.e(TAG, "Interstitial ad displayed.");
}

@Override
public void onError(Ad ad, AdError adError) {
// Ad error callback
Log.e(TAG, "Interstitial ad failed to load: " + adError.getErrorMessage());
}



@Override
public void onAdLoaded(Ad ad) {
// Interstitial ad is loaded and ready to be displayed
Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!");


}

// Show the ad
interstitialAd.show();
}

最佳答案

在 onCreate 中调用此

private void requestInterstitialAd(){
interstitialAd = new InterstitialAd(this, getResources().getString(R.string.interstitial_ad_id)); //YOUR_PLACEMENT_ID
interstitialAd.loadAd();
}

在您想要加载广告的位置使用此代码,并在启动计时器完成后使用它

if(interstitialAd.isAdLoaded()) {
interstitialAd.show();
interstitialAd.setAdListener(new InterstitialAdListener() {

@Override
public void onError(Ad ad, AdError adError) {
}
@Override
public void onInterstitialDismissed(Ad ad) {
requestInterstitialAd();
//Perform your functionality here
}
@Override
public void onInterstitialDisplayed(Ad ad) {
}
@Override
public void onAdLoaded(Ad ad) {
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onLoggingImpression(Ad ad) {

}
});
}
else {
requestInterstitialAd();
//Perform your functionality here in case ad is not loaded before
}

关于java - 将 InterstitialAd 与 InterstitialAdListener 结合使用。获取错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820654/

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