插页式Admob不起作用:未定义AFMA_ReceiveMessage

Cyr*_*obé 1 android ads interstitial admob

我有两种广告:横幅广告和插页式广告.第一个效果非常好,但是当我按下后退按钮时我想要显示插页式广告(但我们不关心按钮),在关闭我的应用之前.但我的插页式广告不起作用,我的应用程序正在关闭日志中的此错误:

E/Ads(20984): JS: Uncaught ReferenceError: AFMA_ReceiveMessage is not defined (:1)
Run Code Online (Sandbox Code Playgroud)

我不知道这个错误意味着什么.我浏览了互联网,它可能来自我的互联网连接.我的Wifi?或者它可能来自Admob?

我应该尝试更好的联系吗?

谢谢你的帮助.

pho*_*van 5

我的代码用于添加InterstitialAdd:

public static void addInterstitialAd(final Activity context, final int id) {
    final InterstitialAd interstitial = new InterstitialAd(context);
    interstitial.setAdUnitId(context.getString(id));
    interstitial.loadAd(new AdRequest.Builder().build());
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Call displayInterstitial() function
            if (interstitial.isLoaded()) {
                interstitial.show();
            }
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

你可以尝试一下,如果不行,请分开到新线程:

 new Thread(new Runnable() {
        public void run() {
        final InterstitialAd interstitial = new InterstitialAd(context);
        interstitial.setAdUnitId(context.getString(id));
        interstitial.loadAd(new AdRequest.Builder().build());
        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Call displayInterstitial() function
                if (interstitial.isLoaded()) {
                runOnUiThread(new Runnable() {
                public void run() {
                    interstitial.show();
                }
              });                
             }
            }
        });
     }
    }).start();
Run Code Online (Sandbox Code Playgroud)

如果您想要点击后退 - > Admod-> close admod - > apclose:

@Override
    public void onBackPressed() {
        final InterstitialAd interstitial = new InterstitialAd(getApplicationContext());
        interstitial.setAdUnitId(getApplicationContext().getString(id));
        interstitial.loadAd(new AdRequest.Builder().build());
        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Call displayInterstitial() function
                if (interstitial.isLoaded()) {
                    interstitial.show();
                }
            }
            @Override
            public void onAdClosed(){
                finish();
            }
            @Override
            public void onAdFailedToLoad(int errorCode){
                //you can implement continue load or finish 
            }

        });
    }
Run Code Online (Sandbox Code Playgroud)