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

标签 java android facebook-audience-network

我在使用 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/

相关文章:

java - RycyclerView android 中的 Facebook 原生广告

java - ORM/DSL 中返回的浮点类型

java - 双重计算产生奇怪的结果

android - Gradle 插件 v0.13.1 后的重复 Zip 条目

android - 在 CoordinatorLayout 内的 Cardview 内带有 EditText 的 NestedScrollview 不填充视口(viewport)

java - 如何在 Fedora 中查找和查看 Java 包和类?

java - 如何根据 searchView 输入过滤字符串

android - 如何在没有 fragment 的情况下共享 Activity 之间的通用布局

android - Facebook受众群体网络:“预计”支出未显示在“版式”部分中